Пример #1
0
        public void GetRequestByIdShouldReturnRequestById()
        {
            var options = new DbContextOptionsBuilder <BookStoreDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            //

            var dbContext = new BookStoreDbContext(options);

            var userRequestService = new UserRequestsService(dbContext);

            var listOfUserRequests = new List <UserRequest>
            {
                new UserRequest()
                {
                    Id = 2, Title = "Test"
                },
                new UserRequest()
                {
                    Id = 1, Title = "Test"
                }
            };

            dbContext.UserRequests.AddRange(listOfUserRequests);
            dbContext.SaveChanges();

            var isReurntRequestById = userRequestService.GetRequestById(1);

            Assert.True(isReurntRequestById != null);
            Assert.True(isReurntRequestById.Title == "Test");
        }
Пример #2
0
        public void DeleteShouldDeleteRequestFromDb()
        {
            var options = new DbContextOptionsBuilder <BookStoreDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            //

            var dbContext = new BookStoreDbContext(options);

            var userRequestService = new UserRequestsService(dbContext);
            var listOfUserRequests = new List <UserRequest>
            {
                new UserRequest()
                {
                    Id = 2, Title = "Test"
                },
                new UserRequest()
                {
                    Id = 1, Title = "Test"
                }
            };

            dbContext.UserRequests.AddRange(listOfUserRequests);
            dbContext.SaveChanges();

            var isReurntRequestById         = userRequestService.Delete(1);
            var tryToGetDeleteElementFromDb = dbContext.UserRequests.Where(x => x.Id == 1).ToList();

            Assert.True(isReurntRequestById);
            Assert.True(tryToGetDeleteElementFromDb.Count == 0);
        }
Пример #3
0
        public void GetUnseenRequestsShouldReturnListWithUnseenRequests()
        {
            var options = new DbContextOptionsBuilder <BookStoreDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            //

            var dbContext = new BookStoreDbContext(options);

            var userRequestService = new UserRequestsService(dbContext);

            var title   = "Question";
            var email   = "*****@*****.**";
            var content = "content";

            userRequestService.Create(title, email, content);
            userRequestService.Create(title + 1, email, content);

            userRequestService.Unseen(1);
            userRequestService.Unseen(2);

            var unSeenListOfRequest = userRequestService.GetUnseenRequests().ToList();

            Assert.True(unSeenListOfRequest != null);
            Assert.True(unSeenListOfRequest.Count == 2);
        }
        public void DeleteShouldReturnTrueAndDeleteUserRequest()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "Delete_UserRequests_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var userRequestsService = new UserRequestsService(dbContext);

            var userRequestId    = 1;
            var userRequestTitle = "Request-1";

            dbContext.UserRequests.AddRange(new List <UserRequest>
            {
                new UserRequest {
                    Id = userRequestId, Title = userRequestTitle, Seen = true
                },
                new UserRequest {
                    Id = 2, Title = "Request-2"
                },
                new UserRequest {
                    Id = 3, Title = "Request-3"
                },
            });
            dbContext.SaveChanges();

            var isDeleted = userRequestsService.Delete(userRequestId);

            var userRequest = dbContext.UserRequests.FirstOrDefault(x => x.Id == userRequestId);

            Assert.Null(userRequest);
            Assert.True(isDeleted);
        }
Пример #5
0
        public void UnSeenShouldSerSeenOnFalse()
        {
            var options = new DbContextOptionsBuilder <BookStoreDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            //

            var dbContext = new BookStoreDbContext(options);

            var userRequestService = new UserRequestsService(dbContext);

            var listOfUserRequests = new List <UserRequest>
            {
                new UserRequest()
                {
                    Id = 2, Title = "Test"
                },
                new UserRequest()
                {
                    Id = 1, Title = "Test"
                }
            };

            dbContext.UserRequests.AddRange(listOfUserRequests);
            dbContext.SaveChanges();

            userRequestService.Unseen(1);
            var isSeenSetToTrue = dbContext.UserRequests.Where(x => x.Id == 1).FirstOrDefault();

            Assert.True(isSeenSetToTrue.Seen == false);
        }
        public void GetRequestByIdShouldReturnUserRequest()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetRequestById_UserRequests_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var userRequestsService = new UserRequestsService(dbContext);

            var userRequestId    = 1;
            var userRequestTitle = "Request-1";

            dbContext.UserRequests.AddRange(new List <UserRequest>
            {
                new UserRequest {
                    Id = userRequestId, Title = userRequestTitle
                },
                new UserRequest {
                    Id = 2, Title = "Request-2"
                },
                new UserRequest {
                    Id = 3, Title = "Request-3"
                },
            });
            dbContext.SaveChanges();

            var userRequest = userRequestsService.GetRequestById(userRequestId);

            Assert.Equal(userRequestTitle, userRequest.Title);
            Assert.Equal(userRequestId, userRequest.Id);
        }
        public void GetUnseenRequestsShouldReturneAllGetUnSeenRequests()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetUnseenRequests_UserRequests_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var userRequestsService = new UserRequestsService(dbContext);

            var userRequestId    = 1;
            var userRequestTitle = "Request-1";

            dbContext.UserRequests.AddRange(new List <UserRequest>
            {
                new UserRequest {
                    Id = userRequestId, Title = userRequestTitle, Seen = true
                },
                new UserRequest {
                    Id = 2, Title = "Request-2"
                },
                new UserRequest {
                    Id = 3, Title = "Request-3"
                },
            });
            dbContext.SaveChanges();

            var unseenRequests = userRequestsService.GetUnseenRequests();

            Assert.Equal(2, unseenRequests.Count());
        }
        public void UnseenShouldChangeIsSeenOnFalse()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "Unseen_UserRequests_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var userRequestsService = new UserRequestsService(dbContext);

            var userRequestId    = 1;
            var userRequestTitle = "Request-1";

            dbContext.UserRequests.AddRange(new List <UserRequest>
            {
                new UserRequest {
                    Id = userRequestId, Title = userRequestTitle, Seen = true
                },
                new UserRequest {
                    Id = 2, Title = "Request-2"
                },
                new UserRequest {
                    Id = 3, Title = "Request-3"
                },
            });
            dbContext.SaveChanges();

            userRequestsService.Unseen(userRequestId);

            var userRequest = dbContext.UserRequests.FirstOrDefault(x => x.Id == userRequestId);

            Assert.False(userRequest.Seen);
        }
Пример #9
0
        public async Task CreateAsyncShouldCreateRequestSuccessfully()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            var userRequestsService = new UserRequestsService(dbContext);

            await userRequestsService.CreateAsync(UserRequestFullName, UserRequestEmail, UserRequestContent);

            var actual = await dbContext.UserRequests.FirstOrDefaultAsync();

            Assert.Equal(actual.FullName, UserRequestFullName);
        }
Пример #10
0
        public void AllShouldReturnListWithRequestSaveInDB()
        {
            var options = new DbContextOptionsBuilder <BookStoreDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            //

            var dbContext = new BookStoreDbContext(options);

            var userRequestService = new UserRequestsService(dbContext);

            var title   = "Question";
            var email   = "*****@*****.**";
            var content = "content";

            userRequestService.Create(title, email, content);
            userRequestService.Create(title + 1, email, content);

            var isReurntallRequests = userRequestService.All().ToList();

            Assert.True(isReurntallRequests != null);
            Assert.True(isReurntallRequests.Count == 2);
        }
Пример #11
0
        public void CreateShoulCreteUserRequestAndSaveInDb()
        {
            var options = new DbContextOptionsBuilder <BookStoreDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            //

            var dbContext = new BookStoreDbContext(options);

            var userRequestService = new UserRequestsService(dbContext);

            var title   = "Question";
            var email   = "*****@*****.**";
            var content = "content";

            userRequestService.Create(title, email, content);

            var userRequestFronDb = dbContext.UserRequests.FirstOrDefault();

            Assert.True(userRequestFronDb != null);
            Assert.True(userRequestFronDb.Title == title);
            Assert.True(userRequestFronDb.Email == email);
            Assert.True(userRequestFronDb.Content == content);
        }
        public void AllShouldReturnAllUserRequest()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "All_UserRequests_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var userRequestsService = new UserRequestsService(dbContext);

            dbContext.UserRequests.AddRange(new List <UserRequest>
            {
                new UserRequest {
                    Title = "Question", Content = "content"
                },
                new UserRequest {
                    Title = "Request", Content = "content1"
                }
            });
            dbContext.SaveChanges();

            var userRequests = userRequestsService.All();

            Assert.Equal(2, userRequests.Count());
        }
        public void CreateShouldCreateUserRequest()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "Create_UserRequests_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var userRequestsService = new UserRequestsService(dbContext);

            var title   = "Question";
            var email   = "*****@*****.**";
            var content = "content";

            userRequestsService.Create(title, email, content);

            var userRequests = dbContext.UserRequests.ToList();

            Assert.Single(userRequests);
            Assert.Equal(title, userRequests.First().Title);
            Assert.Equal(email, userRequests.First().Email);
            Assert.Equal(content, userRequests.First().Content);
            Assert.Equal(DateTime.UtcNow.AddHours(GlobalConstants.BULGARIAN_HOURS_FROM_UTC_TIME).Hour,
                         userRequests.First().RequestDate.Hour);
        }
        private UserRequestsService GetUserRequestService(EfDeletableEntityRepository <UserRequest> userRequestRepository)
        {
            var userRequestService = new UserRequestsService(userRequestRepository);

            return(userRequestService);
        }