예제 #1
0
        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);
        }
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        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")
            };
        }
예제 #10
0
        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);
        }
예제 #11
0
        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;
        }