public async Task GetOrAddAeDeliveryLocation_IgnoresCaseOfApprovalNumberAndOperatorName()
        {
            // Arrange
            var dbContextHelper = new DbContextHelper();
            var context         = A.Fake <WeeeContext>();

            var aeDeliveryLocations = dbContextHelper.GetAsyncEnabledDbSet(new List <AeDeliveryLocation>());

            A.CallTo(() => context.AeDeliveryLocations)
            .Returns(aeDeliveryLocations);

            var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy <Scheme>(), A.Dummy <Quarter>(), context);

            // Act
            var result1 = await dataAccess.GetOrAddAeDeliveryLocation("AAA", "BBB");

            var result2 = await dataAccess.GetOrAddAeDeliveryLocation("aaa", "BBB");

            var result3 = await dataAccess.GetOrAddAeDeliveryLocation("AAA", "bbb");

            var result4 = await dataAccess.GetOrAddAeDeliveryLocation("aaa", "bbb");

            // Assert
            Assert.Contains(result1, dataAccess.CachedAeDeliveryLocations.Values);
            Assert.Same(result1, result2);
            Assert.Same(result1, result3);
            Assert.Same(result1, result4);
            A.CallTo(() => aeDeliveryLocations.Add(A <AeDeliveryLocation> ._))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
        public async Task GetOrAddAeDeliveryLocation_NoMatchingOperatorName_ReturnsNewAeDeliveryLocation(string suppliedOperatorName, string resultingOperatorName)
        {
            // Arrange
            var dbContextHelper = new DbContextHelper();
            var context         = A.Fake <WeeeContext>();

            var aeDeliveryLocationDb = new AeDeliveryLocation("AAA", "xxx");
            var aeDeliveryLocations  = dbContextHelper.GetAsyncEnabledDbSet(new List <AeDeliveryLocation> {
                aeDeliveryLocationDb
            });

            A.CallTo(() => context.AeDeliveryLocations)
            .Returns(aeDeliveryLocations);

            var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy <Scheme>(), A.Dummy <Quarter>(), context);

            // Act
            var result = await dataAccess.GetOrAddAeDeliveryLocation("AAA", suppliedOperatorName);

            // Assert
            Assert.NotNull(result);
            Assert.NotSame(aeDeliveryLocationDb, result);
            Assert.Equal("AAA", result.ApprovalNumber);
            Assert.Equal(resultingOperatorName, result.OperatorName);
            Assert.Contains(result, dataAccess.CachedAeDeliveryLocations.Values);
            A.CallTo(() => aeDeliveryLocations.Add(result))
            .MustHaveHappened();
        }
Esempio n. 3
0
        public async Task GetOrAddAeDeliveryLocation_ReturnsAeDeliveryLocation_ForMatchingOperatorName()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(database.Model);

                helper.CreateAeDeliveryLocation("APR", "Operator Name1");
                var location = helper.CreateAeDeliveryLocation("APR", "Operator Name2");

                database.Model.SaveChanges();

                var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy <Domain.Scheme.Scheme>(), A.Dummy <Quarter>(), database.WeeeContext);

                // Act
                var result = await dataAccess.GetOrAddAeDeliveryLocation("APR", "Operator Name2");

                // Assert
                Assert.NotNull(result);
                Assert.Equal("Operator Name2", result.OperatorName);
                Assert.Equal(location.Id, result.Id);
            }
        }
        public async Task GetOrAddAeDeliveryLocation_PopulatesCacheWithDatabaseValues(string approvalNumber, string operatorName)
        {
            // Arrange
            var dbContextHelper = new DbContextHelper();
            var context         = A.Fake <WeeeContext>();

            var aeDeliveryLocationDb = new AeDeliveryLocation(approvalNumber, operatorName);
            var aeDeliveryLocations  = dbContextHelper.GetAsyncEnabledDbSet(new List <AeDeliveryLocation> {
                aeDeliveryLocationDb
            });

            A.CallTo(() => context.AeDeliveryLocations)
            .Returns(aeDeliveryLocations);

            var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy <Scheme>(), A.Dummy <Quarter>(), context);

            // Act
            await dataAccess.GetOrAddAeDeliveryLocation(approvalNumber, operatorName);

            // Assert
            Assert.Equal(1, dataAccess.CachedAeDeliveryLocations.Count);
            Assert.Contains(aeDeliveryLocationDb, dataAccess.CachedAeDeliveryLocations.Values);
        }
        public async Task GetOrAddAeDeliveryLocation_WithMatchingApprovalNumberAndOperatorName_DoesNotAddToCacheAndDatabase(string approvalNumber, string operatorName)
        {
            // Arrange
            var dbContextHelper = new DbContextHelper();
            var context         = A.Fake <WeeeContext>();

            var aeDeliveryLocationDb = new AeDeliveryLocation(approvalNumber, operatorName);
            var aeDeliveryLocations  = dbContextHelper.GetAsyncEnabledDbSet(new List <AeDeliveryLocation> {
                aeDeliveryLocationDb
            });

            A.CallTo(() => context.AeDeliveryLocations)
            .Returns(aeDeliveryLocations);

            var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy <Scheme>(), A.Dummy <Quarter>(), context);

            // Act
            var result = await dataAccess.GetOrAddAeDeliveryLocation(approvalNumber, operatorName);

            // Assert
            Assert.Equal(1, dataAccess.CachedAeDeliveryLocations.Count);
            A.CallTo(() => aeDeliveryLocations.Add(result))
            .MustNotHaveHappened();
        }
        public async Task GetOrAddAeDeliveryLocation_ReturnsAeDeliveryLocation_ForMatchingOperatorName()
        {
            using (DatabaseWrapper database = new DatabaseWrapper())
            {
                // Arrange
                ModelHelper helper = new ModelHelper(database.Model);

                helper.CreateAeDeliveryLocation("APR", "Operator Name1");
                var location = helper.CreateAeDeliveryLocation("APR", "Operator Name2");

                database.Model.SaveChanges();

                var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy<Domain.Scheme.Scheme>(), A.Dummy<Quarter>(), database.WeeeContext);

                // Act
                var result = await dataAccess.GetOrAddAeDeliveryLocation("APR", "Operator Name2");

                // Assert
                Assert.NotNull(result);
                Assert.Equal("Operator Name2", result.OperatorName);
                Assert.Equal(location.Id, result.Id);
            }
        }
        public async Task GetOrAddAeDeliveryLocation_IgnoresCaseOfApprovalNumberAndOperatorName()
        {
            // Arrange
            var dbContextHelper = new DbContextHelper();
            var context = A.Fake<WeeeContext>();

            var aeDeliveryLocations = dbContextHelper.GetAsyncEnabledDbSet(new List<AeDeliveryLocation>());
            A.CallTo(() => context.AeDeliveryLocations)
                .Returns(aeDeliveryLocations);

            var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy<Scheme>(), A.Dummy<Quarter>(), context);

            // Act
            var result1 = await dataAccess.GetOrAddAeDeliveryLocation("AAA", "BBB");
            var result2 = await dataAccess.GetOrAddAeDeliveryLocation("aaa", "BBB");
            var result3 = await dataAccess.GetOrAddAeDeliveryLocation("AAA", "bbb");
            var result4 = await dataAccess.GetOrAddAeDeliveryLocation("aaa", "bbb");

            // Assert
            Assert.Contains(result1, dataAccess.CachedAeDeliveryLocations.Values);
            Assert.Same(result1, result2);
            Assert.Same(result1, result3);
            Assert.Same(result1, result4);
            A.CallTo(() => aeDeliveryLocations.Add(A<AeDeliveryLocation>._))
                .MustHaveHappened(Repeated.Exactly.Once);
        }
        public async Task GetOrAddAeDeliveryLocation_NoMatchingApprovalNumberAndOperatorName_ReturnsNewAeDeliveryLocation()
        {
            // Arrange
            var dbContextHelper = new DbContextHelper();
            var context = A.Fake<WeeeContext>();

            var aeDeliveryLocations = dbContextHelper.GetAsyncEnabledDbSet(new List<AeDeliveryLocation>());
            A.CallTo(() => context.AeDeliveryLocations)
                .Returns(aeDeliveryLocations);

            var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy<Scheme>(), A.Dummy<Quarter>(), context);

            // Act
            var result = await dataAccess.GetOrAddAeDeliveryLocation("AAA", "BBB");

            // Assert
            Assert.NotNull(result);
            Assert.Equal("AAA", result.ApprovalNumber);
            Assert.Equal("BBB", result.OperatorName);
            Assert.Contains(result, dataAccess.CachedAeDeliveryLocations.Values);
            A.CallTo(() => aeDeliveryLocations.Add(result))
                .MustHaveHappened();
        }
        public async Task GetOrAddAeDeliveryLocation_WithMatchingApprovalNumberAndOperatorName_DoesNotAddToCacheAndDatabase(string approvalNumber, string operatorName)
        {
            // Arrange
            var dbContextHelper = new DbContextHelper();
            var context = A.Fake<WeeeContext>();

            var aeDeliveryLocationDb = new AeDeliveryLocation(approvalNumber, operatorName);
            var aeDeliveryLocations = dbContextHelper.GetAsyncEnabledDbSet(new List<AeDeliveryLocation> { aeDeliveryLocationDb });
            A.CallTo(() => context.AeDeliveryLocations)
                .Returns(aeDeliveryLocations);

            var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy<Scheme>(), A.Dummy<Quarter>(), context);

            // Act
            var result = await dataAccess.GetOrAddAeDeliveryLocation(approvalNumber, operatorName);

            // Assert
            Assert.Equal(1, dataAccess.CachedAeDeliveryLocations.Count);
            A.CallTo(() => aeDeliveryLocations.Add(result))
                .MustNotHaveHappened();
        }
        public async Task GetOrAddAeDeliveryLocation_PopulatesCacheWithDatabaseValues(string approvalNumber, string operatorName)
        {
            // Arrange
            var dbContextHelper = new DbContextHelper();
            var context = A.Fake<WeeeContext>();

            var aeDeliveryLocationDb = new AeDeliveryLocation(approvalNumber, operatorName);
            var aeDeliveryLocations = dbContextHelper.GetAsyncEnabledDbSet(new List<AeDeliveryLocation> { aeDeliveryLocationDb });
            A.CallTo(() => context.AeDeliveryLocations)
                .Returns(aeDeliveryLocations);

            var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy<Scheme>(), A.Dummy<Quarter>(), context);

            // Act
            await dataAccess.GetOrAddAeDeliveryLocation(approvalNumber, operatorName);

            // Assert
            Assert.Equal(1, dataAccess.CachedAeDeliveryLocations.Count);
            Assert.Contains(aeDeliveryLocationDb, dataAccess.CachedAeDeliveryLocations.Values);
        }