コード例 #1
0
        public async Task MultpliplePeopleMatchingFilter_GetMultipleByFilterWithOrderBy_AllMatchingFilterResultsReturnedOrdered()
        {
            //Arrange
            const byte numberOfPeople = 10;
            const byte minimalAge     = 10;
            var        repository     = await CompositeKeyRepositoryArranger.TryGetRepositoryAsync().ConfigureAwait(false);

            var localRepo = new List <CompsiteKeyPerson>(numberOfPeople);

            for (var i = 0; i < numberOfPeople; i++)
            {
                var  postfix = (i + 1).ToString();
                byte age     = (byte)(i + minimalAge);
                var  person  = CompositeKeyRepositoryArranger.CreatePerson(age, postfix, postfix);
                localRepo.Add(person);
                var addOpRes = await repository.TryAddAsync(person)
                               .ConfigureAwait(false);

                Assert.IsTrue(addOpRes, addOpRes.ErrorMessage);
            }

            //Act
            var getOpRes = await repository.TryGetMultipleAsync(p => p.Age >= minimalAge,
                                                                orderBy : people => people.OrderBy(p => p.Age))
                           .ConfigureAwait(false);

            //Assert
            Assert.IsTrue(getOpRes, getOpRes.ErrorMessage);
            Assert.AreEqual(numberOfPeople, getOpRes.Value.TotalNumberOfItems);
            Assert.IsTrue(localRepo.OrderBy(p => p.Age).SequenceEqual(getOpRes.Value.Items));
        }
コード例 #2
0
        public async Task ExistingPerson_Update_Updated()
        {
            //Arrange
            const string updatedValue = "Updated";
            var          repository   = await CompositeKeyRepositoryArranger.TryGetRepositoryAsync().ConfigureAwait(false);

            var person   = CompositeKeyRepositoryArranger.CreatePerson();
            var addOpRes = await repository.TryAddAsync(person)
                           .ConfigureAwait(false);

            var existingEntityId = new object[] { addOpRes.Value.Key1, addOpRes.Value.Key2, addOpRes.Value.Key3 };

            Assert.IsTrue(addOpRes, addOpRes.ErrorMessage);
            var getOpRes = await repository.TryGetSingleAsync(existingEntityId)
                           .ConfigureAwait(false);

            Assert.IsTrue(getOpRes, getOpRes.ErrorMessage);
            Assert.AreEqual(getOpRes.Value, addOpRes.Value);

            //Act
            var updateOpRes = await repository.TryUpdateAsync(existingEntityId,
                                                              p =>
            {
                p.FirstName = updatedValue;
                p.LastName  = updatedValue;
            }).ConfigureAwait(false);

            //Assert
            Assert.IsTrue(updateOpRes, updateOpRes.ErrorMessage);
            getOpRes = await repository.TryGetSingleAsync(existingEntityId).ConfigureAwait(false);

            Assert.AreEqual(getOpRes.Value.FirstName, updatedValue);
            Assert.AreEqual(getOpRes.Value.LastName, updatedValue);
        }
コード例 #3
0
        private static async Task <CompsiteKeyPerson> CreateAndCommitPersonAsync(
            EFCoreCompositeKeyUnitOfWorkRepositoryFor <CompsiteKeyPerson> unitOfWork)
        {
            var person   = CompositeKeyRepositoryArranger.CreatePerson();
            var addOpRes = await unitOfWork.Repository.TryAddAsync(person);

            Assert.IsTrue(addOpRes, addOpRes.ErrorMessage);
            var commitOpRes = await unitOfWork.TryCommitChangesAsync().ConfigureAwait(false);

            Assert.IsTrue(commitOpRes, commitOpRes.ErrorMessage);
            return(person);
        }
コード例 #4
0
        public async Task NonExistingPerson_Add_Added()
        {
            //Arrange
            var repository = await CompositeKeyRepositoryArranger.TryGetRepositoryAsync()
                             .ConfigureAwait(false);

            var person = CompositeKeyRepositoryArranger.CreatePerson();

            //Act
            var opRes = await repository.TryAddAsync(person)
                        .ConfigureAwait(false);

            //Assert
            Assert.IsTrue(opRes, opRes.ErrorMessage);
        }
コード例 #5
0
        public async Task NonExistingPerson_Add_Added()
        {
            //Arrange
            var unitOfWork = await CompositeKeyRepositoryArranger.TryGetUnitOfWorkRepositoryAsync().ConfigureAwait(false);

            var person = CompositeKeyRepositoryArranger.CreatePerson();

            //Act
            var addOpRes = await unitOfWork.Repository.TryAddAsync(person).ConfigureAwait(false);

            var saveOpRes = await unitOfWork.TryCommitChangesAsync().ConfigureAwait(false);

            //Assert
            Assert.IsTrue(addOpRes, addOpRes.ErrorMessage);
            Assert.IsTrue(saveOpRes, saveOpRes.ErrorMessage);
        }
        public async Task GetMultipleWithPaging_SingleItemPerPage_ExpectedNumberOfPagesWithResultsReturned()
        {
            //Arrange
            const byte numberOfPeople = 10;
            const byte minimalAge     = 10;
            var        repository     = await CompositeKeyRepositoryArranger
                                        .TryGetRepositoryAsync()
                                        .ConfigureAwait(false);

            for (var i = 0; i < numberOfPeople; i++)
            {
                var  postfix  = (i + 1).ToString();
                byte age      = (byte)(i + minimalAge);
                var  person   = CompositeKeyRepositoryArranger.CreatePerson(age, postfix, postfix);
                var  addOpRes = await repository.TryAddAsync(person)
                                .ConfigureAwait(false);

                Assert.IsTrue(addOpRes, addOpRes.ErrorMessage);
            }

            const int itemsPerPage         = 1;
            int       expctedNumberOfPages = 10;
            int       currentPage          = 1;

            for (int i = 0; i < expctedNumberOfPages; i++)
            {
                //Act
                var getOpRes = await repository.TryGetMultipleAsync(
                    p => p.Age >= minimalAge,
                    pagingParams : new Storage.Common.DataTypes.PagingParams(currentPage, itemsPerPage))
                               .ConfigureAwait(false);

                ++currentPage;

                //Assert
                Assert.IsTrue(getOpRes, getOpRes.ErrorMessage);
                Assert.AreEqual(getOpRes.Value.ItemsPerPage, itemsPerPage);
                Assert.AreEqual(getOpRes.Value.TotalNumberOfPages, expctedNumberOfPages);
                Assert.AreEqual(getOpRes.Value.Items.Count, itemsPerPage);
                Assert.AreEqual(getOpRes.Value.TotalNumberOfItems, numberOfPeople);
            }
        }
コード例 #7
0
        public async Task ExistingPerson_GetSingle_ReturnedExistingPerson()
        {
            //Arrange
            var repository = await CompositeKeyRepositoryArranger.TryGetRepositoryAsync().ConfigureAwait(false);

            var person   = CompositeKeyRepositoryArranger.CreatePerson();
            var addOpRes = await repository.TryAddAsync(person)
                           .ConfigureAwait(false);

            Assert.IsTrue(addOpRes, addOpRes.ErrorMessage);
            var existingEntityId = new object[] { addOpRes.Value.Key1, addOpRes.Value.Key2, addOpRes.Value.Key3 };

            //Act
            var getOpRes = await repository.TryGetSingleAsync(existingEntityId)
                           .ConfigureAwait(false);

            //Assert
            Assert.IsTrue(getOpRes, getOpRes.ErrorMessage);
            Assert.AreEqual(getOpRes.Value, addOpRes.Value);
        }
コード例 #8
0
        public async Task ExistingPerson_Get_ReturnedExistingPerson()
        {
            //Arrange
            var unitOfWork = await CompositeKeyRepositoryArranger
                             .TryGetUnitOfWorkRepositoryAsync()
                             .ConfigureAwait(false);

            var person   = CompositeKeyRepositoryArranger.CreatePerson();
            var addOpRes = await unitOfWork.Repository.TryAddAsync(person);

            Assert.IsTrue(addOpRes, addOpRes.ErrorMessage);
            var commitOpRes = await unitOfWork.TryCommitChangesAsync().ConfigureAwait(false);

            Assert.IsTrue(commitOpRes, commitOpRes.ErrorMessage);

            //Act
            var getOpRes = await unitOfWork.Repository.TryGetSingleAsync(
                new object[] { person.Key1, person.Key2, person.Key3 })
                           .ConfigureAwait(false);

            //Assert
            Assert.IsTrue(getOpRes, getOpRes.ErrorMessage);
            Assert.AreEqual(getOpRes.Value, person);
        }