Esempio n. 1
0
        public async Task Sort_Should_Sort_Users_Into_Correct_Order_When_Ascending()
        {
            // Arrange...
            var inMemoryContext = InMemoryContextHelper.Create();

            InMemoryContextHelper.AddUsersToContext(_fixture, inMemoryContext, 3);
            var sut        = new UserRepository(inMemoryContext);
            var getOptions = new GetOptions();
            var ordering   = new Ordering("FirstName", SortOrder.Ascending);

            getOptions.AddOrdering(ordering);

            // Act...
            var pageOfUsers = await sut.Get(getOptions);

            // Assert...
            pageOfUsers.Should().NotBeNull();
            pageOfUsers.Count.Should().Be(3);
            pageOfUsers.TotalCount.Should().Be(3);
            var orderedInMemoryUsers = inMemoryContext.Users.OrderBy(x => x.FirstName);
            var firstUser            = orderedInMemoryUsers.Skip(0).Take(1);
            var secondUser           = orderedInMemoryUsers.Skip(1).Take(1);
            var thirdUser            = orderedInMemoryUsers.Skip(2).Take(1);

            pageOfUsers.Skip(0).Take(1).Should().BeEquivalentTo(firstUser);
            pageOfUsers.Skip(1).Take(1).Should().BeEquivalentTo(secondUser);
            pageOfUsers.Skip(2).Take(1).Should().BeEquivalentTo(thirdUser);
        }
Esempio n. 2
0
        public async Task Persistence_PagedList_To_API_PagedList()
        {
            // Arrange...
            _fixture.RepeatCount = 10;
            var users           = _fixture.Create <List <User> >();
            var inMemoryContext = InMemoryContextHelper.Create();

            InMemoryContextHelper.AddUsersToContext(inMemoryContext, users);
            var pagedListUsers = await Persistence.Models.PagedList <User> .CreateAsync(inMemoryContext.Users, 1, 5);

            var configuration = new MapperConfiguration(configure =>
            {
                configure.AddProfile <PersistencePagedListToApiPagedList>();
            });
            var sut = configuration.CreateMapper();

            // Act...
            var pagedListUserResponses = sut.Map <API.Models.v1.PagedList <UserResponse> >(pagedListUsers);

            // Assert...
            pagedListUserResponses.Count.Should().Be(pagedListUsers.PageSize);
            pagedListUserResponses.CurrentPage.Should().Be(pagedListUsers.CurrentPage);
            pagedListUserResponses.PageSize.Should().Be(pagedListUsers.PageSize);
            pagedListUserResponses.HasPrevious.Should().Be(pagedListUsers.HasPrevious);
            pagedListUserResponses.HasNext.Should().Be(pagedListUsers.HasNext);
            pagedListUserResponses.TotalCount.Should().Be(pagedListUsers.TotalCount);
            pagedListUserResponses.TotalPages.Should().Be(pagedListUsers.TotalPages);
        }
Esempio n. 3
0
        public async Task Get_With_Pagination_Options_Should_Return_PageList_With_Page_1_When_30_Users_Exists()
        {
            // Arrange...
            var inMemoryContext = InMemoryContextHelper.Create();

            InMemoryContextHelper.AddUsersToContext(_fixture, inMemoryContext, 30);
            var sut             = new UserRepository(inMemoryContext);
            var getUsersOptions = new GetOptions
            {
                PageSize   = 10,
                PageNumber = 1
            };

            // Act...
            var pagedList = await sut.Get(getUsersOptions);

            // Assert...
            pagedList.Should().NotBeNull();
            pagedList.Count.Should().Be(10);
            pagedList.TotalCount.Should().Be(30);
            pagedList.CurrentPage.Should().Be(1);
            pagedList.TotalPages.Should().Be(3);
            pagedList.HasPrevious.Should().BeFalse();
            pagedList.HasNext.Should().BeTrue();
        }
        private IUnitOfWork GetUnitOfWork(out DataContext inMemoryContext)
        {
            inMemoryContext = InMemoryContextHelper.Create();
            var userRepository      = new UserRepository(inMemoryContext);
            var dt                  = _fixture.Create <DateTime>();
            var mockDateTimeService = MockDateTimeServiceHelper.Create(dt);
            var unitOfWork          = new Persistence.UnitOfWork(inMemoryContext, mockDateTimeService, userRepository);

            return(unitOfWork);
        }
Esempio n. 5
0
        public void Get_With_Null_Options_Should_Throw()
        {
            // Arrange...
            var        inMemoryContext = InMemoryContextHelper.Create();
            var        sut             = new UserRepository(inMemoryContext);
            GetOptions getOptions      = null;

            // Act...
            Func <Task> get = async() => await sut.Get(getOptions);

            // Assert...
            get.Should().Throw <ArgumentNullException>();
        }
Esempio n. 6
0
        public void Find_Should_Not_Return_User_When_User_Is_Not_Findable()
        {
            // Arrange...
            var inMemoryContext = InMemoryContextHelper.Create();

            InMemoryContextHelper.AddUsersToContext(_fixture, inMemoryContext, 1);
            var sut             = new Persistence.Repositories.UserRepository(inMemoryContext);
            var randomFirstName = _fixture.Create <string>();

            // Act...
            var foundUsers = sut.Find(u => u.FirstName == randomFirstName);

            // Assert...
            foundUsers.Should().NotBeNull();
            foundUsers.Count().Should().Be(0);
        }
Esempio n. 7
0
        public async Task Create_Should_Be_Able_To_Add_User()
        {
            // Arrange...
            var user            = _fixture.Create <User>();
            var inMemoryContext = InMemoryContextHelper.Create();
            var userRepository  = new UserRepository(inMemoryContext);
            var dt = _fixture.Create <DateTime>();
            var mockDateTimeService = MockDateTimeServiceHelper.Create(dt);
            var sut = new Persistence.UnitOfWork(inMemoryContext, mockDateTimeService, userRepository);

            // Act...
            sut.UserRepository.Create(user);
            await sut.CompleteAsync();

            // Assert...
            inMemoryContext.Users.Count().Should().Be(1);
            inMemoryContext.Users.First().Should().Be(user);
            user.Id.Should().NotBe(default);
Esempio n. 8
0
        public async Task Get_With_Empty_Options_Should_Return_PagedList_With_No_Users_When_No_Users_Exist()
        {
            // Arrange...
            var inMemoryContext = InMemoryContextHelper.Create();
            var sut             = new UserRepository(inMemoryContext);
            var getUsersOptions = new GetOptions();

            // Act...
            var pagedList = await sut.Get(getUsersOptions);

            // Assert...
            pagedList.Should().BeEmpty();
            pagedList.Count.Should().Be(0);
            pagedList.TotalCount.Should().Be(0);
            pagedList.CurrentPage.Should().Be(0);
            pagedList.TotalPages.Should().Be(0);
            pagedList.HasPrevious.Should().BeFalse();
            pagedList.HasNext.Should().BeFalse();
        }
Esempio n. 9
0
        public async Task Search_Should_Not_Find_Users_That_Do_Not_Match_Search()
        {
            // Arrange...
            var inMemoryContext = InMemoryContextHelper.Create();

            InMemoryContextHelper.AddUsersToContext(_fixture, inMemoryContext, 2);
            var onlyUser   = inMemoryContext.Users.First();
            var sut        = new Persistence.Repositories.UserRepository(inMemoryContext);
            var getOptions = new GetOptions();

            getOptions.SearchQuery = _fixture.Create <string>();

            // Act...
            var pageOfUsers = await sut.Get(getOptions);

            // Assert...
            pageOfUsers.Should().NotBeNull();
            pageOfUsers.Count.Should().Be(0);
            pageOfUsers.TotalCount.Should().Be(0);
        }
Esempio n. 10
0
        public async Task Filter_Should_Exclude_Users_That_Do_Not_Match_Filter()
        {
            // Arrange...
            var inMemoryContext = InMemoryContextHelper.Create();

            InMemoryContextHelper.AddUsersToContext(_fixture, inMemoryContext, 1);
            var onlyUser   = inMemoryContext.Users.First();
            var sut        = new Persistence.Repositories.UserRepository(inMemoryContext);
            var getOptions = new GetOptions();
            var filter     = new Filter("Title", GetDifferent(onlyUser.Title).ToString());

            getOptions.AddFilter(filter);

            // Act...
            var pageOfUsers = await sut.Get(getOptions);

            // Assert...
            pageOfUsers.Should().NotBeNull();
            pageOfUsers.Count.Should().Be(0);
        }
Esempio n. 11
0
        public async Task Get_With_Empty_Options_Should_Return_PageList_With_One_User_When_Only_One_User_Exists()
        {
            // Arrange...
            var inMemoryContext = InMemoryContextHelper.Create();

            InMemoryContextHelper.AddUsersToContext(_fixture, inMemoryContext, 1);
            var sut             = new UserRepository(inMemoryContext);
            var getUsersOptions = new GetOptions();

            // Act...
            var pagedList = await sut.Get(getUsersOptions);

            // Assert...
            pagedList.Should().NotBeNull();
            pagedList.Count.Should().Be(1);
            pagedList.TotalCount.Should().Be(1);
            pagedList.CurrentPage.Should().Be(1);
            pagedList.TotalPages.Should().Be(1);
            pagedList.HasPrevious.Should().BeFalse();
            pagedList.HasNext.Should().BeFalse();
        }