Beispiel #1
0
        public void GetAccountsThatStillNeedProcessingDateTest()
        {
            // Setup
            var cutOfDate = ConvertToDateTime("01-Nov-2018");

            List <Accounts> testAccountTable = new List <Accounts>
            {
                new Accounts {
                    Name = "Well Before Date", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "ACTIVATED", Createtimestamp = cutOfDate.AddDays(-50)
                },
                new Accounts {
                    Name = "One Day Before Date", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "ACTIVATED", Createtimestamp = cutOfDate.AddDays(-1)
                },
                new Accounts {
                    Name = "On Cut Off Date", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "ACTIVATED", Createtimestamp = cutOfDate
                },
                new Accounts {
                    Name = "After Cut Off Daye", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "ACTIVATED", Createtimestamp = cutOfDate.AddDays(1)
                }
            };
            var fakeDbSet = Aef.FakeDbSet(testAccountTable);

            A.CallTo(() => fakeDbContext.Accounts).Returns(fakeDbSet);

            // Act
            var results = repo.GetAccountsThatStillNeedProcessing(cutOfDate);

            // Assert
            results.Count().Should().Be(2);
        }
Beispiel #2
0
        public void GetAccountsThatStillNeedProcessingStatesTest()
        {
            // Setup
            var cutOfDate = ConvertToDateTime("31-Oct-2018");

            List <Accounts> testAccountTable = new List <Accounts>
            {
                new Accounts {
                    Name = "ACTIVATED", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "ACTIVATED", Createtimestamp = cutOfDate
                },
                new Accounts {
                    Name = "PENDINGACTIVATION", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "PENDINGACTIVATION", Createtimestamp = cutOfDate
                },
                new Accounts {
                    Name = "INITIAL", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "INITIAL", Createtimestamp = cutOfDate
                },
                new Accounts {
                    Name = "PENDINGRESET", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "PENDINGRESET", Createtimestamp = cutOfDate
                },
            };
            var fakeDbSet = Aef.FakeDbSet(testAccountTable);

            A.CallTo(() => fakeDbContext.Accounts).Returns(fakeDbSet);

            // Act
            var results = repo.GetAccountsThatStillNeedProcessing(cutOfDate.AddDays(1));

            // Assert should get the one Activated and Pending Activation.
            results.Count().Should().Be(2);
        }
Beispiel #3
0
        public void GetAccountsThatStillNeedProcessingDateTest()
        {
            // Setup
            var fakeDbContext = A.Fake <DFCUserAccountsContext>();
            var repo          = new CircuitBreakerQuery(fakeDbContext);

            var lastCircuitOpenDate = DateTime.Now;

            List <CircuitBreaker> testCircuitBreakerData = new List <CircuitBreaker>
            {
                new CircuitBreaker {
                    CircuitBreakerStatus = CircuitBreakerStatus.Open.ToString(), HalfOpenRetryCount = 1, LastCircuitOpenDate = lastCircuitOpenDate
                },
                new CircuitBreaker {
                    CircuitBreakerStatus = CircuitBreakerStatus.Closed.ToString(), HalfOpenRetryCount = 0, LastCircuitOpenDate = lastCircuitOpenDate
                },
            };

            var fakeCircuitBreakerDbSet = Aef.FakeDbSet(testCircuitBreakerData);

            A.CallTo(() => fakeDbContext.CircuitBreaker).Returns(fakeCircuitBreakerDbSet);

            // Act
            var result = repo.GetBreakerDetails();

            // Assert
            result.Should().NotBeNull();
            result.HalfOpenRetryCount.Should().Be(1);
            result.CircuitBreakerStatus.Should().Be(CircuitBreakerStatus.Open);
            result.LastCircuitOpenDate.Should().Be(lastCircuitOpenDate);
        }
Beispiel #4
0
        public async void Setup()
        {
            var dbContext = new OrderDbContext
            {
                Orders = Aef.FakeDbSet(orders)
            };

            placedAtDate = DateTime.UtcNow;
            orderId      = new Guid("DE81F6B5-7F29-4AE7-A72B-023F6B58DE72");
            var placeOrderCommand = new PlaceOrderCommand
            {
                OrderId      = orderId,
                OrderNumber  = 100,
                PlacedAtDate = placedAtDate
            };

            var context = new TestableMessageHandlerContext();

            var orderStorageContextMock = new Mock <IDbContextWrapper <OrderDbContext> >();

            orderStorageContextMock.SetupIgnoreArgs(x => x.Get(null)).Returns(dbContext);

            handler = new PlaceOrderCommandHandler(orderStorageContextMock.Object);

            await handler.Handle(placeOrderCommand, context);

            await dbContext.SaveChangesAsync();
        }
Beispiel #5
0
        public CircuitBreakerCommandRepositoryTests()
        {
            fakeDbContext           = A.Fake <DFCUserAccountsContext>();
            repo                    = new CircuitBreakerCommandRepository(this.fakeDbContext);
            testCircuitBreakerTable = new List <CircuitBreaker>();
            var fakeCircuitBreakerDbSet = Aef.FakeDbSet(this.testCircuitBreakerTable);

            A.CallTo(() => fakeDbContext.CircuitBreaker).Returns(fakeCircuitBreakerDbSet);
        }
        public AuditCommandRepositoryTests()
        {
            fakeDbContext  = A.Fake <DFCUserAccountsContext>();
            repo           = new AuditCommandRepository(this.fakeDbContext);
            testAuditTable = new List <Audit>();
            var fakeAuditDbSet = Aef.FakeDbSet(this.testAuditTable);

            A.CallTo(() => fakeDbContext.Audit).Returns(fakeAuditDbSet);
        }
        public void Remove_ShouldRemoveItem()
        {
            var fakeDbSet = Aef.FakeDbSet(new List <TestModel> {
                new TestModel(), new TestModel()
            });
            var toRemove = fakeDbSet.First();

            fakeDbSet.Remove(toRemove);

            CollectionAssert.DoesNotContain(fakeDbSet.ToList(), toRemove);
        }
        public void AddRange_ShouldAddItems()
        {
            var fakeDbSet = Aef.FakeDbSet(new List <TestModel> {
                new TestModel(), new TestModel()
            });
            var newModels = new[] { new TestModel(), new TestModel() };

            fakeDbSet.AddRange(newModels);

            CollectionAssert.IsSubsetOf(newModels, fakeDbSet.ToList());
        }
        public void Add_ShouldAddItem()
        {
            var fakeDbSet = Aef.FakeDbSet(new List <TestModel> {
                new TestModel(), new TestModel()
            });
            var newModel = new TestModel();

            fakeDbSet.Add(newModel);

            CollectionAssert.Contains(fakeDbSet.ToList(), newModel);
        }
        public void AddRange_ShouldAddItems()
        {
            var fakeDbSet = Aef.FakeDbSet(new List <TestModel> {
                new TestModel(), new TestModel()
            });
            var newModels = new[] { new TestModel(), new TestModel() };

            fakeDbSet.AddRange(newModels);

            Assert.True(fakeDbSet.Except(newModels).Count() == 2);
        }
Beispiel #11
0
        public void GetAccountsThatStillNeedProcessingProcessingStatesTest()
        {
            // Setup
            var cutOfDate = ConvertToDateTime("31-Oct-2018");

            List <Accounts> testAccountTable = new List <Accounts>
            {
                new Accounts {
                    Name = "Not In Audit", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "ACTIVATED", Createtimestamp = cutOfDate
                },
                new Accounts {
                    Name = "In Audit - Processing", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "ACTIVATED", Createtimestamp = cutOfDate
                },
                new Accounts {
                    Name = "In Audit - Circuit Got Broken", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "ACTIVATED", Createtimestamp = cutOfDate
                },
                new Accounts {
                    Name = "In Audit - Failed", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "ACTIVATED", Createtimestamp = cutOfDate
                },
                new Accounts {
                    Name = "In Audit - Completed", Mail = "*****@*****.**", Uid = "*****@*****.**", A1lifecycleState = "ACTIVATED", Createtimestamp = cutOfDate
                }
            };
            var fakeDbSet = Aef.FakeDbSet(testAccountTable);

            A.CallTo(() => fakeDbContext.Accounts).Returns(fakeDbSet);

            testAuditTable.Add(new Audit {
                Email = "*****@*****.**", Status = NotificationProcessingStatus.InProgress.ToString()
            });
            testAuditTable.Add(new Audit {
                Email = "*****@*****.**", Status = NotificationProcessingStatus.CircuitGotBroken.ToString()
            });
            testAuditTable.Add(new Audit {
                Email = "*****@*****.**", Status = NotificationProcessingStatus.InProgress.ToString()
            });
            testAuditTable.Add(new Audit {
                Email = "*****@*****.**", Status = NotificationProcessingStatus.Failed.ToString()
            });
            testAuditTable.Add(new Audit {
                Email = "*****@*****.**", Status = NotificationProcessingStatus.InProgress.ToString()
            });
            testAuditTable.Add(new Audit {
                Email = "*****@*****.**", Status = NotificationProcessingStatus.Completed.ToString()
            });

            // Act
            var results = repo.GetAccountsThatStillNeedProcessing(cutOfDate.AddDays(1));

            // Assert should have the one that not in Audit and the broken circuit one
            results.Count().Should().Be(2);
        }
        public void Remove_ShouldNotThrowWhenIteratingThrough()
        {
            var fakeDbSet = Aef.FakeDbSet(new List <TestModel> {
                new TestModel(), new TestModel()
            });

            fakeDbSet.Remove(fakeDbSet.First());

            foreach (var model in fakeDbSet)
            {
                Assert.Pass();
            }
        }
        public void AddRange_ShouldNotThrowWhenIteratingThrough()
        {
            var fakeDbSet = Aef.FakeDbSet(new List <TestModel> {
                new TestModel(), new TestModel()
            });

            fakeDbSet.AddRange(new[] { new TestModel(), new TestModel() });

            foreach (var model in fakeDbSet)
            {
                Assert.Pass();
            }
        }
        public void Add_ShouldNotThrowWhenIteratingThrough()
        {
            var fakeDbSet = Aef.FakeDbSet(new List <TestModel> {
                new TestModel(), new TestModel()
            });

            fakeDbSet.Add(new TestModel());

            foreach (var model in fakeDbSet)
            {
                Assert.NotNull(model);
            }
        }
Beispiel #15
0
        public async void Setup()
        {
            var dbContext = new OrderDbContext()
            {
                Orders = Aef.FakeDbSet(orders)
            };

            placedAtDate = DateTime.UtcNow;
            orderId      = new Guid("DE81F6B5-7F29-4AE7-A72B-023F6B58DE72");
            var placeOrderCommand = new PlaceOrderCommand
            {
                OrderId      = orderId,
                OrderNumber  = 100,
                PlacedAtDate = placedAtDate
            };

            var context = new TestableMessageHandlerContext();

            //TODO: Question? How do you test this, since I cannot inject the OrderDbContext into the handler
            //In the handler there is the context.SynchronizedStorageSession.FromCurrentSession() that returns a new OrderDbContext
            //In V5 we did new PlaceOrderCommandHandler(OrderDbContext dbContext); and then we could use the FakeDbSet.
            //Since I could not use Moq to mock the return value of context.SynchronizedStorageSession.FromCurrentSession() since it is an extension method
            //so I created a OrderStorageContext instead
            //Then I realized that U guys have your own TestingFramework that I installed so that I could get a TestableMessageHandlerContext
            //but cannot find a way to set the session.SqlPersistenceSession();

            var orderStorageContextMock = new Mock <IDbContextWrapper <OrderDbContext> >();

            orderStorageContextMock.SetupIgnoreArgs(x => x.GetDbContext(null)).Returns(dbContext);


            handler = new PlaceOrderCommandHandler(orderStorageContextMock.Object);

            try
            {
                await handler.Handle(placeOrderCommand, context)
                .ConfigureAwait(false);

                await dbContext.SaveChangesAsync()
                .ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public void RemoveRange_ShouldRemoveItems()
        {
            var fakeDbSet = Aef.FakeDbSet(new List <TestModel>
            {
                new TestModel {
                    Property = "a"
                },
                new TestModel {
                    Property = "a"
                },
                new TestModel {
                    Property = "b"
                }
            });

            fakeDbSet.RemoveRange(fakeDbSet.Where(x => x.Property == "a"));

            Assert.That(fakeDbSet.Count(), Is.EqualTo(1));
        }
        public async Task CountAsync_ShouldReturnListCount()
        {
            var fakeDbSet = Aef.FakeDbSet(
                new List <TestModel> {
                new TestModel {
                    Id = 1, Property = "apple"
                },
                new TestModel {
                    Id = 2, Property = "banana"
                },
                new TestModel {
                    Id = 3, Property = "Grape"
                }
            });

            var result = await fakeDbSet.CountAsync();

            Assert.Equal(3, result);
        }
        public async Task AllAsync_ShouldReturnTrue()
        {
            var fakeDbSet = Aef.FakeDbSet(
                new List <TestModel> {
                new TestModel {
                    Id = 1, Property = "apple"
                },
                new TestModel {
                    Id = 2, Property = "banana"
                },
                new TestModel {
                    Id = 3, Property = "Grape"
                }
            });

            var result = await fakeDbSet.AllAsync(e => e.Property.Contains("a"));

            Assert.True(result);
        }
        public async Task FirstOrDefaultAsync_ShouldReturnFilteredSinlgeItem()
        {
            var fakeDbSet = Aef.FakeDbSet(
                new List <TestModel> {
                new TestModel {
                    Id = 1, Property = "apple"
                },
                new TestModel {
                    Id = 2, Property = "banana"
                },
                new TestModel {
                    Id = 3, Property = "Cherry"
                }
            });

            var items = await fakeDbSet.FirstOrDefaultAsync(e => e.Property.Equals("Cherry"));

            Assert.Equal("Cherry", items.Property);
        }
        public async Task WhereAsync_ShouldReturnFilteredItems()
        {
            var fakeDbSet = Aef.FakeDbSet(
                new List <TestModel> {
                new TestModel {
                    Id = 1, Property = "apple"
                },
                new TestModel {
                    Id = 2, Property = "banana"
                },
                new TestModel {
                    Id = 3, Property = "Cherry"
                }
            });

            var items = await fakeDbSet.Where(e => e.Property.Contains("a")).ToListAsync();

            Assert.Equal(2, items.Count);
        }
        public void AllAsync_ShouldReturnTrue()
        {
            var fakeDbSet = Aef.FakeDbSet(
                new List <TestModel> {
                new TestModel {
                    Id = 1, Property = "apple"
                },
                new TestModel {
                    Id = 2, Property = "banana"
                },
                new TestModel {
                    Id = 3, Property = "Grape"
                }
            });

            var result = fakeDbSet.AllAsync(e => e.Property.Contains("a")).Result;


            Assert.AreEqual(result, true);
        }
        public void FirstOrDefaultAsync_ShouldReturnFilteredSinlgeItem()
        {
            var fakeDbSet = Aef.FakeDbSet(
                new List <TestModel> {
                new TestModel {
                    Id = 1, Property = "apple"
                },
                new TestModel {
                    Id = 2, Property = "banana"
                },
                new TestModel {
                    Id = 3, Property = "Cherry"
                }
            });

            var items = fakeDbSet.FirstOrDefaultAsync(e => e.Property.Equals("Cherry")).Result;


            Assert.AreEqual(items.Property, "Cherry");
        }
        public void WhereAsync_ShouldReturnFilteredItems()
        {
            var fakeDbSet = Aef.FakeDbSet(
                new List <TestModel> {
                new TestModel {
                    Id = 1, Property = "apple"
                },
                new TestModel {
                    Id = 2, Property = "banana"
                },
                new TestModel {
                    Id = 3, Property = "Cherry"
                }
            });

            var items = fakeDbSet.Where(e => e.Property.Contains("a")).ToListAsync().Result;


            Assert.AreEqual(items.Count(), 2);
        }
        public void CountAsync_ShouldReturnListCount()
        {
            var fakeDbSet = Aef.FakeDbSet(
                new List <TestModel> {
                new TestModel {
                    Id = 1, Property = "apple"
                },
                new TestModel {
                    Id = 2, Property = "banana"
                },
                new TestModel {
                    Id = 3, Property = "Grape"
                }
            });

            var result = fakeDbSet.CountAsync().Result;


            Assert.AreEqual(result, 3);
        }
Beispiel #25
0
        public void GetAccountsThatStillNeedProcessingMapingTest()
        {
            // Setup
            var             cutOfDate        = ConvertToDateTime("31-Oct-2018");
            List <Accounts> testAccountTable = new List <Accounts>
            {
                new Accounts {
                    Name = nameof(Accounts.Name), Mail = nameof(Accounts.Mail), Uid = nameof(Accounts.Name), A1lifecycleState = "ACTIVATED", Createtimestamp = cutOfDate.AddDays(-50)
                },
            };
            var fakeDbSet = Aef.FakeDbSet(testAccountTable);

            A.CallTo(() => fakeDbContext.Accounts).Returns(fakeDbSet);

            // Act
            var results = repo.GetAccountsThatStillNeedProcessing(cutOfDate.AddDays(1));

            // Assert
            results.Count().Should().Be(1);
            var account = results.FirstOrDefault();

            account.Name.Should().Be(nameof(Accounts.Name));
            account.EMail.Should().Be(nameof(Accounts.Mail));
        }
        public void AsNoTracking_ReturnsItSelf()
        {
            var fakeDbSet = Aef.FakeDbSet(new List <TestModel>());

            Assert.AreSame(fakeDbSet, fakeDbSet.AsNoTracking());
        }
        public void Include_ReturnsItSelf()
        {
            var fakeDbSet = Aef.FakeDbSet(new List <TestModel>());

            Assert.AreSame(fakeDbSet, fakeDbSet.Include("asdas"));
        }