public void ValidateTravel_Invalid() { var mockContext = new Mock<ApplicationDbContext>(); var locationMockDbSet = new MockDbSet<Location>(); mockContext.Setup(m => m.Locations).Returns(locationMockDbSet.DbSet.Object); var entryCharMockDbSet = new MockDbSet<EntryLocationCharacter>(); mockContext.Setup(m => m.EntryLocationCharacters).Returns(entryCharMockDbSet.DbSet.Object); var service = new TravelService(mockContext.Object); var result = service.ValidateTravel("tag", 1); Assert.IsFalse(result.IsValid); Assert.AreEqual(result.Messages.Count(), 2); }
public void ValidateTravel_Valid() { var mockContext = new Mock<ApplicationDbContext>(); var locationMockDbSet = new MockDbSet<Location>(); locationMockDbSet.Add(new Location { Tag = "tag", Type = ModelEnums.LocationType.City }); mockContext.Setup(m => m.Locations).Returns(locationMockDbSet.DbSet.Object); var entryCharMockDbSet = new MockDbSet<EntryLocationCharacter>(); entryCharMockDbSet.Add(new EntryLocationCharacter { Arrival = DateTime.Now.AddHours(-1), Character_Id = 1 }); mockContext.Setup(m => m.EntryLocationCharacters).Returns(entryCharMockDbSet.DbSet.Object); var service = new TravelService(mockContext.Object); var result = service.ValidateTravel("tag", 1); Assert.IsTrue(result.IsValid); }