Exemple #1
0
        public async Task UpdateHive_UpdateHiveToExistedCode_ExceptionThrown(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var existedhive = new StoreHive
            {
                Id   = 1,
                Code = "Code"
            };

            var updatedExistedHive = new StoreHive
            {
                Id   = 2,
                Code = "Code1"
            };

            var newHive = new UpdateHiveRequest
            {
                Code = "Code"
            };

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new[] { existedhive, updatedExistedHive });

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.UpdateHiveAsync(2, newHive));
        }
        public async void CreateHiveSuccesFull()
        {
            var productContext = new Mock <IProductStoreHiveContext>();

            productContext.Setup(p => p.Hives).ReturnsEntitySet(new List <StoreHive>());

            var userContext = new Mock <IUserContext>();

            userContext.Setup(u => u.UserId).Returns(1);

            var dbHive = new StoreHive
            {
                Id   = 1,
                Code = "12314321"
            };

            var myProductMock =
                new ProductStoreContextMock(new FakeEntitySet <StoreHive>(new List <StoreHive> {
                dbHive
            }), null, null);

            var service = new HiveService(productContext.Object, userContext.Object);

            var createRequest = new UpdateHiveRequest
            {
                Name    = "newHive",
                Address = "address",
                Code    = "111341"
            };
            await service.CreateHiveAsync(createRequest);

            //Assert.NotNull(service.GetHivesAsync());
        }
Exemple #3
0
        public async Task GetHives_HiveAndChainedSection_HiveListItemWithProperlyCountedSections(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var hive = new StoreHive
            {
                Id = 1
            };

            var hiveSection = new StoreHiveSection
            {
                Id          = 1,
                StoreHive   = hive,
                StoreHiveId = 1
            };

            hive.Sections = new[] { hiveSection };

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new[] { hive });
            context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new[] { hiveSection });

            var result = await service.GetHivesAsync();

            Assert.True(result[0].HiveSectionCount == 1);
        }
Exemple #4
0
        public async Task GetHive_RequestWithUnExistedId_ExceptionThrown(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var hive = new StoreHive
            {
                Id = 1
            };

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new[] { hive });

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.GetHiveAsync(2));
        }
Exemple #5
0
        public async Task DeleteHive_DeletingHiveWithUndeletedStatus_ExceptionThrown(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var hive = new StoreHive
            {
                Id        = 1,
                IsDeleted = false
            };

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new[] { hive });

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.DeleteHiveAsync(hive.Id));
        }
Exemple #6
0
        public async Task GetHive_RequestWithExistedId_HiveReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var hive = new StoreHive
            {
                Id = 1
            };

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new[] { hive });

            var resultHive = await service.GetHiveAsync(1);

            Assert.True(hive.Id == resultHive.Id);
        }
Exemple #7
0
        public async Task CreateHive_CreateHiveWithExistedCode_ExceptionThrown(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var hive = new StoreHive
            {
                Id   = 1,
                Code = "Code"
            };

            var newHive = new UpdateHiveRequest
            {
                Code = hive.Code
            };

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new[] { hive });

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.CreateHiveAsync(newHive));
        }
Exemple #8
0
        public async Task DeleteHiveAsync_IdAsParametr_StatusIsDeletedTrue()
        {
            var list = new StoreHive[1]
            {
                new StoreHive {
                    Id = 3, Code = "HIVE3", IsDeleted = true
                }
            };

            var hiveId = 3;

            var storeContext = new Mock <IProductStoreHiveContext>();
            var userContext  = new Mock <IUserContext>();

            storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(list);

            var service = new HiveService(storeContext.Object, userContext.Object);

            await service.DeleteHiveAsync(hiveId);
        }
        public async Task SetStatusAsync_SetHiveStatus(int hiveId, bool hiveStatusBefor, bool hiveStatusAfter)
        {
            var storeHive = new StoreHive();

            storeHive.Id = hiveId;

            storeHive.IsDeleted = hiveStatusBefor;

            Assert.Equal(hiveStatusBefor, storeHive.IsDeleted);

            var storeHives = new[] { storeHive };

            _context.Setup(s => s.Hives).ReturnsEntitySet(storeHives);

            var service = new HiveService(_context.Object, _userContext.Object);

            await service.SetStatusAsync(hiveId, hiveStatusAfter);

            Assert.Equal(hiveStatusAfter, storeHive.IsDeleted);
        }
Exemple #10
0
        public async Task UpdateHive_TryUpdateHive_UpdatedHiveReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var existedhive = new StoreHive
            {
                Id   = 1,
                Code = "Code"
            };

            var newHive = new UpdateHiveRequest
            {
                Code = "newCode"
            };

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new[] { existedhive });

            var updatedHive = await service.UpdateHiveAsync(existedhive.Id, newHive);

            Assert.True(updatedHive.Code == newHive.Code);
        }
Exemple #11
0
        public async Task GetHiveSections_SetWithTenHiveSectionsAndHiveId_ListWithFilteredHiveSectionsReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var firstHive = new StoreHive
            {
                Id = 1
            };
            string firstHiveName = "FirstHive";

            fixture.Customize <StoreHiveSection>(c => c.Without(x => x.StoreHive)
                                                 .Without(x => x.Items)
                                                 .Without(x => x.Categories)
                                                 .With(x => x.Name, firstHiveName)
                                                 .With(x => x.StoreHiveId, firstHive.Id)
                                                 .With(x => x.StoreHive, firstHive));
            var chainedToFirstHive = fixture.CreateMany <StoreHiveSection>(5).ToArray();

            var secondHive = new StoreHive
            {
                Id = 2
            };
            string secondHiveName = "SecondHive";

            fixture.Customize <StoreHiveSection>(c => c.Without(x => x.StoreHive)
                                                 .Without(x => x.Items)
                                                 .Without(x => x.Categories)
                                                 .With(x => x.Name, secondHiveName)
                                                 .With(x => x.StoreHiveId, secondHive.Id)
                                                 .With(x => x.StoreHive, secondHive));
            var chainedToSecondHive = fixture.CreateMany <StoreHiveSection>(5).ToArray();

            context.Setup(c => c.Sections).ReturnsAsyncEntitySet(chainedToFirstHive.Concat(chainedToSecondHive).ToArray());

            var result = await service.GetHiveSectionsAsync(firstHive.Id);

            Assert.True(chainedToSecondHive.Length == result.Count);
            Assert.All(result, h => h.Name.Equals(secondHiveName));
        }