Exemplo n.º 1
0
        public async Task RemoveReturnScheme_GivenSchemeIdsAndReturn_EntitiesShouldBeRemoved()
        {
            using (var database = new DatabaseWrapper())
            {
                var helper       = new ModelHelper(database.Model);
                var domainHelper = new DomainHelper(database.WeeeContext);
                var dataAccess   = new ReturnSchemeDataAccess(database.WeeeContext);

                var @return             = ObligatedWeeeIntegrationCommon.CreateReturn(null, database.Model.AspNetUsers.First().Id, FacilityType.Aatf);
                var aatf                = ObligatedWeeeIntegrationCommon.CreateAatf(database, @return.Organisation);
                var scheme              = new EA.Weee.Domain.Scheme.Scheme(@return.Organisation);
                var weeeReceived        = new EA.Weee.Domain.AatfReturn.WeeeReceived(scheme, aatf, @return);
                var weeeReceivedAmounts = new Domain.AatfReturn.WeeeReceivedAmount(weeeReceived, 1, null, null);
                var returnScheme        = new Domain.AatfReturn.ReturnScheme(scheme, @return);

                database.WeeeContext.Returns.Add(@return);
                database.WeeeContext.Organisations.Add(@return.Organisation);
                database.WeeeContext.Aatfs.Add(aatf);
                database.WeeeContext.Schemes.Add(scheme);
                database.WeeeContext.WeeeReceived.Add(weeeReceived);
                database.WeeeContext.WeeeReceivedAmount.Add(weeeReceivedAmounts);
                database.WeeeContext.ReturnScheme.Add(returnScheme);

                await database.WeeeContext.SaveChangesAsync();

                await dataAccess.RemoveReturnScheme(new List <Guid>() { scheme.Id }, @return.Id);

                database.WeeeContext.ReturnScheme.Count(r => r.SchemeId == scheme.Id).Should().Be(0);
                database.WeeeContext.WeeeReceived.Count(r => r.SchemeId == scheme.Id).Should().Be(0);
                database.WeeeContext.WeeeReceivedAmount.Count(r => r.WeeeReceived.Id == weeeReceived.Id).Should().Be(0);

                database.WeeeContext.Schemes.Count(s => s.Id == scheme.Id).Should().Be(1);
                database.WeeeContext.Returns.Count(r => r.Id == @return.Id).Should().Be(1);
            }
        }
        public async Task RemoveReturnScheme_GivenSchemeIdReturnId_PCSforReturnShouldBeReturned()
        {
            var returnId        = Guid.NewGuid();
            var returnIdNoMatch = Guid.NewGuid();
            var schemeId1       = Guid.NewGuid();
            var schemeIds       = new List <Guid>();

            schemeIds.Add(schemeId1);

            var returnSchemeMatch   = A.Fake <ReturnScheme>();
            var returnSchemeNoMatch = A.Fake <ReturnScheme>();

            A.CallTo(() => returnSchemeMatch.Scheme).Returns(A.Fake <Scheme>());
            A.CallTo(() => returnSchemeMatch.SchemeId).Returns(schemeId1);
            A.CallTo(() => returnSchemeMatch.ReturnId).Returns(returnId);

            A.CallTo(() => returnSchemeNoMatch.Scheme).Returns(A.Fake <Scheme>());
            A.CallTo(() => returnSchemeNoMatch.SchemeId).Returns(schemeId1);
            A.CallTo(() => returnSchemeNoMatch.ReturnId).Returns(returnIdNoMatch);

            List <WeeeReceived> weeeReceived = new List <WeeeReceived>();

            WeeeReceived weee  = new WeeeReceived(schemeId1, A.Dummy <Guid>(), returnId);
            WeeeReceived weee1 = new WeeeReceived(schemeId1, A.Dummy <Guid>(), returnIdNoMatch);

            weeeReceived.Add(weee);
            weeeReceived.Add(weee1);

            var list = new List <WeeeReceivedAmount>();
            var weeeReceivedAmount = A.Fake <WeeeReceivedAmount>();

            A.CallTo(() => weeeReceivedAmount.Id).Returns(A.Dummy <Guid>());
            list.Add(weeeReceivedAmount);
            A.CallTo(() => context.WeeeReceivedAmount).Returns(dbHelper.GetAsyncEnabledDbSet(list));

            A.CallTo(() => context.WeeeReceived).Returns(dbHelper.GetAsyncEnabledDbSet(weeeReceived));
            A.CallTo(() => context.ReturnScheme).Returns(dbHelper.GetAsyncEnabledDbSet(new List <ReturnScheme>()
            {
                returnSchemeNoMatch, returnSchemeMatch
            }));

            await dataAccess.RemoveReturnScheme(schemeIds, returnId);

            A.CallTo(() => context.WeeeReceived.Remove(weee)).MustHaveHappened(Repeated.Exactly.Once)
            .Then(A.CallTo(() => context.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once));
            A.CallTo(() => context.ReturnScheme.Remove(returnSchemeMatch)).MustHaveHappened(Repeated.Exactly.Once)
            .Then(A.CallTo(() => context.SaveChangesAsync()).MustHaveHappened(Repeated.Exactly.Once));
        }