Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dj-nitehawk committed Aug 11, 2020
1 parent 60a1034 commit 16e9794
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion MongoDB.Entities/MongoDB.Entities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReleaseNotes>- [breaking] remove MongoDB.Entities.Core namespace
- [breaking] make ModifiedOn property opt-in using IModifiedOn interface
- [breaking] remove support for geo haystack indexes as deprecated in official driver
- new interface ICreatedOn for optionally adding creation date to entities
- new interface ICreatedOn for optionally adding auto-managed creation date to entities
- misc. changes</PackageReleaseNotes>
<PackageId>MongoDB.Entities</PackageId>
<Product>MongoDB.Entities</Product>
Expand Down
4 changes: 3 additions & 1 deletion Tests/Models/Author.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace MongoDB.Entities.Tests
{
[Name("Writer")]
public class Author : Entity, IModifiedOn
public class Author : Entity, IModifiedOn, ICreatedOn
{
public string Name { get; set; }
public string Surname { get; set; }
Expand All @@ -30,6 +30,8 @@ public class Author : Entity, IModifiedOn
public string BookIDs { get; set; }

public DateTime ModifiedOn { get; set; }

public DateTime CreatedOn { get; set; }

public Author() => this.InitOneToMany(() => Books);
}
Expand Down
16 changes: 16 additions & 0 deletions Tests/TestSaving.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ public void saved_book_has_correct_title()
Assert.AreEqual("Test", title);
}

[TestMethod]
public void created_on_property_works()
{
var author = new Author { Name = "test" };
author.Save();

var res = DB.Find<Author, DateTime>()
.Match(a => a.ID == author.ID)
.Project(a => a.CreatedOn)
.Execute()
.Single();

Assert.AreEqual(res.ToLongTimeString(), author.CreatedOn.ToLongTimeString());
Assert.IsTrue(DateTime.UtcNow.Subtract(res).TotalSeconds <= 5);
}

[TestMethod]
public void save_preserving()
{
Expand Down

0 comments on commit 16e9794

Please sign in to comment.