public void Delete_NonExisting_ExceptionThrown() { Post post = new Post() { ID = Guid.NewGuid(), PostData = "Data", PostDate = DateTime.Now, RelationID = this.TestPost2.RelationID }; PostRepository Repository = new PostRepository(helper); Repository.Delete(post); Assert.IsNull(Repository.GetByID(post.ID).ID); }
public void Delete_Existing_RecordDeleted() { Post post = new Post() { ID = Guid.NewGuid(), PostData = "Data", PostDate = DateTime.Now, RelationID = this.TestPost2.RelationID }; PostRepository Repository = new PostRepository(helper); Repository.Insert(post); Repository.Delete(post); Assert.AreEqual(null, Repository.GetByID(post.ID)); }
public void AddPost_ValidPost_TrueFlag() { Post post = new Post(); post.ID = Guid.NewGuid(); post.PostData = "data"; Mock<IRepository<Post>> repository = new Mock<IRepository<Post>>(); Mock<ILoggerService> loggerService = new Mock<ILoggerService>(); Mock<IMediaService> mediaService = new Mock<IMediaService>(); Mock<IFileService> fileService = new Mock<IFileService>(); repository.Setup(o => o.Insert(post)); PostService service = new PostService(repository.Object, loggerService.Object, mediaService.Object, fileService.Object); bool flag = service.AddPost(post); Assert.IsTrue(flag); }
public void GetPost_ExistingPost_ReturnsPost() { Post post = new Post(); post.ID = Guid.NewGuid(); post.PostData = "data"; Mock<IRepository<Post>> repository = new Mock<IRepository<Post>>(); Mock<ILoggerService> loggerService = new Mock<ILoggerService>(); Mock<IMediaService> mediaService = new Mock<IMediaService>(); Mock<IFileService> fileService = new Mock<IFileService>(); repository.SetupSequence(o => o.GetByID(post.ID)).Returns(post); PostService service = new PostService(repository.Object, loggerService.Object, mediaService.Object, fileService.Object); Post result = service.GetPost(post.ID); Assert.AreEqual(post, result); }
public void GetPosts_PostsExist_ReturnsList() { IList<Post> posts = new List<Post>(); for (int i = 0; i < 2; i++) { Post post = new Post(); post.ID = Guid.NewGuid(); post.PostData = "data"; post.PostDate = DateTime.Now; posts.Add(post); } Mock<IRepository<Post>> repository = new Mock<IRepository<Post>>(); Mock<ILoggerService> loggerService = new Mock<ILoggerService>(); Mock<IMediaService> mediaService = new Mock<IMediaService>(); Mock<IFileService> fileService = new Mock<IFileService>(); repository.Setup(o => o.GetAll()).Returns(posts); PostService service = new PostService(repository.Object, loggerService.Object, mediaService.Object, fileService.Object); IList<Post> result = service.GetPosts(); Assert.AreEqual(posts.Count, result.Count); }
public void GetLocations_TripExistsWithLocations_ReturnsList() { Guid tripID = Guid.NewGuid(); Trip trip = new Trip() { ID = tripID, Posts = new List<Post>(), }; Post Posts1 = new Post() { ID = Guid.NewGuid(), PostLat = "123", PostLong = "145", PostDate = DateTime.Now }; Post Posts2 = new Post() { ID = Guid.NewGuid(), PostLat = "123", PostLong = "145", PostDate = DateTime.Now }; trip.Posts.Add(Posts1); trip.Posts.Add(Posts2); Mock<ITripRepository> TripRepository = new Mock<ITripRepository>(); Mock<ILoggerService> loggerService = new Mock<ILoggerService>(); TripRepository.Setup(o => o.GetByID(It.IsAny<Guid>())).Returns(trip); TripService Service = new TripService(TripRepository.Object, loggerService.Object); IList<Location> Locations = Service.GetLocations(Guid.NewGuid()); CollectionAssert.IsNotEmpty(Locations); }
public void Update_NonExistingEntity_Saved() { Post post = new Post() { ID = Guid.NewGuid(), PostData = "Updated Saved", PostDate = DateTime.Now, RelationID = Guid.Parse("E50E7C95-36D3-470C-905E-564321267F20") }; PostRepository Repository = new PostRepository(helper); Repository.Update(post, false); Assert.AreEqual(post.ID, Repository.GetByID(post.ID).ID); }
public void Update_InvalidEntity_ExceptionThrown() { PostRepository Repository = new PostRepository(helper); Post post = new Post() { ID = Guid.NewGuid(), PostData = "InvalidData", PostLat = "123456789123456", PostDate = DateTime.Now, RelationID = Guid.Parse("E50E7C95-36D3-470C-905E-564321267F20") }; Repository.Update(post, false); }
public void SetUp() { Configuration config = new Configuration(); config.DataBaseIntegration(db => { db.Dialect<MsSql2012Dialect>(); db.Driver<SqlClientDriver>(); db.ConnectionString = "Data Source=DESKTOP-0II3UCP\\MAINSERVER;Initial Catalog=travelme;Integrated Security=True"; }); var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); config.AddMapping(mapping); this.MockConfig = new Mock<IDatabaseConfig>(); this.MockConfig.SetupSequence(o => o.GetConfig()).Returns(config); this.helper = new NhibernateHelper(this.MockConfig.Object); this.TestPost = new Post() { ID = Guid.Parse("B1CF1D84-77B1-423B-9BC1-EDE7DB7C6B0B"), PostData = "Test", PostDate = new DateTime(2012,05,08, 10, 0, 0), PostLat = "123", PostLong = "456", RelationID = Guid.Parse("E50E7C95-36D3-470C-905E-564321267F20") }; this.TestPost2 = new Post() { ID = Guid.Parse("5801D5D5-D945-44A2-8CDA-44DB247BAE11"), PostData = "Test2", PostDate = new DateTime(2012, 05, 08, 10, 0, 0), PostLat = "123", PostLong = "456", RelationID = Guid.Parse("E50E7C95-36D3-470C-905E-564321267F20") }; }
public void Insert_NonExistingEntity_Inserted() { Post post = new Post() { ID = Guid.NewGuid(), PostData = "Data", PostDate = DateTime.Now, RelationID = this.TestPost2.RelationID }; PostRepository Repository = new PostRepository(helper); Repository.Insert(post); Assert.AreEqual(post.ID, Repository.GetByID(post.ID).ID); }
public void SetUp() { Configuration config = new Configuration(); config.DataBaseIntegration(db => { db.Dialect<MsSql2012Dialect>(); db.Driver<SqlClientDriver>(); db.ConnectionString = "Data Source=DESKTOP-0II3UCP\\MAINSERVER;Initial Catalog=travelme;Integrated Security=True"; }); var mapper = new ModelMapper(); mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes()); HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); config.AddMapping(mapping); MockConfig = new Mock<IDatabaseConfig>(); MockConfig.SetupSequence(o => o.GetConfig()).Returns(config); helper = new NhibernateHelper(MockConfig.Object); TestUser = new UserEntity() { ID = Guid.Parse("9fc0b724-d55f-441d-a1ae-ec726d7737f7"), FirstName = "Kiran", LastName = "Patel", DateOfBirth = new DateTime(1994, 08, 05, 10, 0, 0), Email = "*****@*****.**", UserPassword = "******", Registered = DateTime.Now, LastLogin = DateTime.Now, InvalidPasswordDate = DateTime.Now }; TestTrip = new Trip() { ID = Guid.Parse("209F9526-3611-4F30-A79C-55557FFBECF5"), TripName = "Australia", TripDescription = "Aussies", TripLocation = "Backpacking", RelationID = Guid.Parse("9fc0b724-d55f-441d-a1ae-ec726d7737f7") }; TestTrip2 = new Trip() { ID = Guid.Parse("6D8BCE5C-5681-472E-A1DC-97C5EA0C23FA"), TripName = "Thailand", TripDescription = "Thai!", TripLocation = "Backpacking", RelationID = Guid.Parse("9fc0b724-d55f-441d-a1ae-ec726d7737f7") }; TestPost = new Post() { ID = Guid.Parse("832B97D6-F958-497A-952D-0224F27C4E1A"), PostData = "PostName", PostLat = "Lat", PostLong = "Long", PostDate = new DateTime(2012,08,09,10,0,0), RelationID = Guid.Parse("209F9526-3611-4F30-A79C-55557FFBECF5") }; TestTrip.Posts.Add(TestPost); TestUser.Trips.Add(TestTrip); TestUser.Trips.Add(TestTrip2); toDeleteUser = new UserEntity() { ID = Guid.NewGuid(), FirstName = "Deleted", LastName = "Deleted", DateOfBirth = new DateTime(1994, 08, 05, 10, 0, 0), Email = "*****@*****.**", UserPassword = "******", InvalidPasswordDate = DateTime.Now, LastLogin = DateTime.Now, Registered = DateTime.Now }; UserEntityRepository ForDelete = new UserEntityRepository(helper); ForDelete.Insert(toDeleteUser); ForDelete = null; }