Ejemplo n.º 1
0
        public async Task DeleteHiveTestAsync_AcceptsWrongId_ThrowsException([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            var hiveId = 1;
            var hives  = fixture.CreateMany <StoreHive>(1).ToList();

            hives[0].Id = 2;
            context.Setup(s => s.Hives).ReturnsEntitySet(hives);
            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.DeleteHiveAsync(hiveId));
        }
        public async void DeleteAsync_ExistedIdentifierFlagIsDeletedFalse_CustomExceptionThrows([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            Configure(context, fixture);
            var id = _hive[0].Id;

            _hive[0].IsDeleted = false;

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.DeleteHiveAsync(id));
        }
Ejemplo n.º 3
0
        public async void DeleteHiveSuccessfull(IFixture fixture, HiveService service,
                                                [Frozen] Mock <IProductStoreHiveContext> productContext, [Frozen] Mock <IUserContext> userContext)
        {
            var hives = fixture.CreateMany <StoreHive>(5).ToList();

            productContext.Setup(p => p.Hives).ReturnsEntitySet(hives);

            await service.DeleteHiveAsync(1);
        }
Ejemplo n.º 4
0
        public async Task DeleteHiveAsync_RequestedResourceNotFoundExceptionThrown([Frozen] Mock <IProductStoreHiveContext> context, HiveService service)
        {
            context.Setup(s => s.Hives).ReturnsEntitySet(new StoreHive[] { });

            var exception = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(
                () => service.DeleteHiveAsync(0));

            Assert.Equal(typeof(RequestedResourceNotFoundException), exception.GetType());
        }
Ejemplo n.º 5
0
        public async Task DeleteHiveTestAsync_WithWrongStatus_ThrowsException([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            var hiveId = 1;
            var hives  = fixture.CreateMany <StoreHive>(1).ToList();

            hives[0].Id        = hiveId;
            hives[0].IsDeleted = false;
            context.Setup(s => s.Hives).ReturnsEntitySet(hives);
            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.DeleteHiveAsync(hiveId));
        }
Ejemplo n.º 6
0
        public void DeleteHiveAsync_NoHiveWithSuchIdTest(int id)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>());
            var service = new HiveService(context.Object, userContext.Object);

            Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.DeleteHiveAsync(id));
        }
        public async void DeleteAsync_ExistedIdentifierFlagIsDeletedTrue_SuccessfulDeleting([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            Configure(context, fixture);
            var id = _hive[0].Id;

            _hive[0].IsDeleted = true;

            await service.DeleteHiveAsync(id);

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetHiveAsync(id));
        }
Ejemplo n.º 8
0
        public async Task DeleteHiveAsync_DeleteNonExistentHive_ExceptionThrown()
        {
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>());
            var service = new HiveService(context.Object, new UserContext());

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() =>
            {
                await service.DeleteHiveAsync(0);
            });
        }
Ejemplo n.º 9
0
        public async Task DeleteHiveAsync_IdAsParametr_NotExistedHiveId_ThrownException()
        {
            var hiveId = 10;

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

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

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

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.DeleteHiveAsync(hiveId));
        }
Ejemplo n.º 10
0
        public async Task DeleteHive_Successfuly_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService)
        {
            var listEntity = fixture.CreateMany <StoreHive>(13).ToList();

            context.Setup(x => x.Hives).ReturnsEntitySet(listEntity);
            context.Setup(x => x.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            await hiveService.SetStatusAsync(listEntity[0].Id, true);

            await hiveService.DeleteHiveAsync(listEntity[0].Id);

            var hives = await hiveService.GetHivesAsync();

            Assert.Equal(12, hives.Count);
        }
        public async Task DeleteHive_RequestedResourceNotFoundException(
            [Frozen] Mock <IProductStoreHiveContext> contex,
            HiveService service,
            IFixture fixture)
        {
            var collection = fixture.CreateMany <StoreHive>(5).ToList();

            contex.Setup(x => x.Hives).ReturnsEntitySet(collection);
            contex.Setup(x => x.Sections).ReturnsEntitySet(new List <StoreHiveSection>());

            Func <Task> act = async() => await service.DeleteHiveAsync(0);

            act.Should().Throw <RequestedResourceNotFoundException>();
        }
Ejemplo n.º 12
0
        public async Task DeleteHiveAsync_PassesHiveId_ThrowsRequestedResourceHasConflictException(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveService hiveService,
            IFixture fixture)
        {
            var storeHives        = fixture.CreateMany <StoreHive>(3).ToList();
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToList();

            contextMock.Setup(c => c.Hives).ReturnsEntitySet(storeHives);
            contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections);
            storeHives[0].IsDeleted = false;

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(
                () => hiveService.DeleteHiveAsync(storeHives[0].Id));
        }
Ejemplo n.º 13
0
        public async Task DeleteHiveAsync_HiveWithTrueStatus_HiveDeleted([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
            fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            var hives = fixture.CreateMany <StoreHive>(1).ToList();

            hives[0].IsDeleted = true;
            context.Setup(c => c.Hives).ReturnsEntitySet(hives);

            await service.DeleteHiveAsync(hives[0].Id);

            var list = await service.GetHivesAsync();

            list.Should().BeEmpty();
        }
Ejemplo n.º 14
0
        public async Task DeleteHiveAsync_PassesHiveId_ExpectsThatCollectionDoesNotContainDeletedHive(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveService hiveService,
            IFixture fixture)
        {
            var storeHives        = fixture.CreateMany <StoreHive>(3).ToList();
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToList();

            contextMock.Setup(c => c.Hives).ReturnsEntitySet(storeHives);
            contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections);
            var deletedHive = storeHives[1];

            await hiveService.DeleteHiveAsync(storeHives[1].Id);

            Assert.DoesNotContain(deletedHive, storeHives);
        }
        public async Task DeleteHive_SetFiveElement_DeleteOne_FourReturned(
            [Frozen] Mock <IProductStoreHiveContext> contex,
            HiveService service,
            IFixture fixture)
        {
            var collection = fixture.CreateMany <StoreHive>(5).ToList();

            contex.Setup(x => x.Hives).ReturnsEntitySet(collection);
            contex.Setup(x => x.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            await service.SetStatusAsync(collection[0].Id, true);

            await service.DeleteHiveAsync(collection[0].Id);

            var result = await service.GetHivesAsync();

            result.Count.Should().Be(4);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        public async Task DeleteHiveAsync_HiveId_Success(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service,
            IFixture fixture)
        {
            var hiveId = 1;

            var dbHives = fixture.CreateMany <StoreHive>(1).ToList();

            dbHives[0].Id = hiveId;

            dbHives[0].IsDeleted = true;

            context.Setup(s => s.Hives).ReturnsEntitySet(dbHives);

            await service.DeleteHiveAsync(hiveId);

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(
                () => service.GetHiveAsync(hiveId));
        }
Ejemplo n.º 18
0
        public async Task DeleteHiveAsync_SuccessfulTest(int id)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1, IsDeleted = true
                }
            });
            var service = new HiveService(context.Object, userContext.Object);

            await service.DeleteHiveAsync(id);

            var hives = await service.GetHivesAsync();

            Assert.Empty(hives);
        }
Ejemplo n.º 19
0
        public async Task DeleteHiveAsync_StatusIsNotDeleted_RequestedResourceHasConflictThrown()
        {
            var mockUserContext       = new Mock <IUserContext>();
            var mockHiveContext       = new Mock <IProductStoreHiveContext>();
            List <StoreHive> hiveList = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1, IsDeleted = false
                },
                new StoreHive()
                {
                    Id = 2
                }
            };

            mockHiveContext.Setup(c => c.Hives).ReturnsEntitySet(hiveList);
            var service = new HiveService(mockHiveContext.Object, mockUserContext.Object);

            Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.DeleteHiveAsync(1));
        }
Ejemplo n.º 20
0
        public async Task DeleteHiveAsync_IdNotPresent_RequestedResourceNotFoundExceptionThrown()
        {
            var mockUserContext       = new Mock <IUserContext>();
            var mockHiveContext       = new Mock <IProductStoreHiveContext>();
            List <StoreHive> hiveList = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1
                },
                new StoreHive()
                {
                    Id = 2
                }
            };

            mockHiveContext.Setup(c => c.Hives).ReturnsEntitySet(hiveList);
            var service = new HiveService(mockHiveContext.Object, mockUserContext.Object);

            Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.DeleteHiveAsync(3));
        }
Ejemplo n.º 21
0
        public async Task DeleteHiveAsync_HiveWithTrueStatus_HiveDeleted()
        {
            var hives = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 0, IsDeleted = true
                },
                new StoreHive()
                {
                    Id = 1, IsDeleted = false
                }
            };
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(hives);
            var service = new HiveService(context.Object, new UserContext());

            await service.DeleteHiveAsync(0);

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.GetHiveAsync(0));
        }
Ejemplo n.º 22
0
        public async Task DeleteHiveAsync_HiveWithFalseStatus_ExceptionThrown()
        {
            var hives = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 0, IsDeleted = true
                },
                new StoreHive()
                {
                    Id = 1, IsDeleted = false
                }
            };
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(hives);
            var service = new HiveService(context.Object, new UserContext());

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() =>
            {
                await service.DeleteHiveAsync(1);
            });
        }
Ejemplo n.º 23
0
        public async Task DeleteHiveAsync_IdPresent_RequestedHiveDeleted()
        {
            var mockUserContext       = new Mock <IUserContext>();
            var mockHiveContext       = new Mock <IProductStoreHiveContext>();
            List <StoreHive> hiveList = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1, IsDeleted = true
                },
                new StoreHive()
                {
                    Id = 2
                }
            };
            List <StoreHiveSection> sectionList = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    StoreHiveId = 1
                },
                new StoreHiveSection()
                {
                    StoreHiveId = 2
                }
            };

            mockHiveContext.Setup(c => c.Hives).ReturnsEntitySet(hiveList);
            mockHiveContext.Setup(c => c.Sections).ReturnsEntitySet(sectionList);
            var service = new HiveService(mockHiveContext.Object, mockUserContext.Object);

            await service.DeleteHiveAsync(1);

            var hives = await service.GetHivesAsync();

            Assert.DoesNotContain(hives, h => h.Id == 1);
        }
Ejemplo n.º 24
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));
        }
Ejemplo n.º 25
0
        public async Task DeleteHive_DeletingHiveWithUnexistedId_ExceptionThrown(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new StoreHive[0]);

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.DeleteHiveAsync(1));
        }
Ejemplo n.º 26
0
        public async Task DeleteHive_ConflictException_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService)
        {
            var listEntity = fixture.CreateMany <StoreHive>(13).ToList();

            context.Setup(x => x.Hives).ReturnsEntitySet(listEntity);
            await hiveService.SetStatusAsync(listEntity[0].Id, false);

            var ex = await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => hiveService.DeleteHiveAsync(listEntity[0].Id));

            Assert.Equal(typeof(RequestedResourceHasConflictException), ex.GetType());
        }
Ejemplo n.º 27
0
        public void DeleteHiveAsync_IsDeletedFalseTest(int id)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1, IsDeleted = false
                }
            });
            var service = new HiveService(context.Object, userContext.Object);

            Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.DeleteHiveAsync(id));
        }