コード例 #1
0
        public async Task CharityUpdatedEventHandler_Handle_Returns_Success()
        {
            SearchContext.OpenInMemoryConnection();

            try
            {
                var content = new Content()
                {
                    Category    = Core.Enums.Category.EnvironmentAndNatureConservation,
                    CharityKey  = Guid.NewGuid(),
                    Image       = "No image given",
                    CharityName = "TestName",
                    Description = "This is a very good testing slogan",
                    Type        = Core.Enums.SearchContentType.Charity
                };

                var updatedCharityEvent = new CharityUpdatedEvent()
                {
                    CharityKey = content.CharityKey,
                    CoverImage = "pretty image",
                    Name       = "Pretty Charity Name",
                    Category   = content.Category,
                    Slogan     = content.Description,
                };

                using (var context = SearchContext.GetInMemoryContext())
                {
                    context.Content.Add(content);
                    context.SaveChanges();
                }

                using (var context = SearchContext.GetInMemoryContext())
                {
                    var handler = new CharityUpdatedEventHandler(context);
                    await handler.ConsumeAsync(updatedCharityEvent);
                }

                using (var context = SearchContext.GetInMemoryContext())
                {
                    Assert.AreEqual(1, context.Content.Count());
                    Assert.AreEqual(content.CharityKey, context.Content.Single().CharityKey);
                    Assert.AreEqual(updatedCharityEvent.CoverImage, context.Content.Single().Image);
                    Assert.AreEqual(content.Category, context.Content.Single().Category);
                    Assert.AreEqual(content.Description, context.Content.Single().Description);
                    Assert.AreEqual(Core.Enums.SearchContentType.Charity, context.Content.Single().Type);
                    Assert.AreEqual(updatedCharityEvent.Name, context.Content.Single().CharityName);
                }
            }
            finally
            {
                SearchContext.CloseInMemoryConnection();
            }
        }
コード例 #2
0
        public async Task CharityUpdatedEventHandler_Handles_Event()
        {
            CharityActionContext.OpenInMemoryConnection();
            try
            {
                var charityUpdatedEvent = new CharityUpdatedEvent
                {
                    CharityKey = Guid.NewGuid(),
                    Name       = "newName"
                };
                var otherKey = Guid.NewGuid();

                using (var context = CharityActionContext.GetInMemoryContext())
                {
                    var charity1 = new Charity
                    {
                        CharityKey = charityUpdatedEvent.CharityKey,
                        Name       = "oldName"
                    };
                    var charity2 = new Charity
                    {
                        CharityKey = otherKey,
                        Name       = "otherOldName"
                    };

                    context.Charities.Add(charity1);
                    context.Charities.Add(charity2);
                    context.SaveChanges();
                }

                using (var context = CharityActionContext.GetInMemoryContext())
                {
                    var handler = new CharityUpdatedEventHandler(context);
                    await handler.ConsumeAsync(charityUpdatedEvent);
                }

                using (var context = CharityActionContext.GetInMemoryContext())
                {
                    Assert.AreEqual(1, context.Charities.Count(a => a.CharityKey == charityUpdatedEvent.CharityKey && a.Name == charityUpdatedEvent.Name));
                    Assert.AreEqual(1, context.Charities.Count(a => a.CharityKey == otherKey && a.Name == "otherOldName"));
                }
            }
            finally
            {
                CharityActionContext.CloseInMemoryConnection();
            }
        }
コード例 #3
0
        public async Task CharityUpdatedEventHandler_Handle_Returns_Success()
        {
            DonationsContext.OpenInMemoryConnection();

            try
            {
                var charity = new Charity()
                {
                    CharityKey = Guid.NewGuid(),
                    Name       = "TestName",
                };

                var updatedCharityEvent = new CharityUpdatedEvent()
                {
                    CharityKey = charity.CharityKey,
                    Name       = "Pretty Charity Name",
                    CoverImage = "new CoverImage",
                    ThankYou   = "ThankYou"
                };

                using (var context = DonationsContext.GetInMemoryContext())
                {
                    context.Charities.Add(charity);
                    context.SaveChanges();
                }

                using (var context = DonationsContext.GetInMemoryContext())
                {
                    var handler = new CharityUpdatedEventHandler(context);
                    await handler.ConsumeAsync(updatedCharityEvent);
                }

                using (var context = DonationsContext.GetInMemoryContext())
                {
                    Assert.AreEqual(1, context.Charities.Count());
                    Assert.AreEqual(updatedCharityEvent.Name, context.Charities.Single().Name);
                    Assert.AreEqual(updatedCharityEvent.ThankYou, context.Charities.Single().ThankYou);
                    Assert.AreEqual(updatedCharityEvent.CoverImage, context.Charities.Single().CoverImage);
                }
            }
            finally
            {
                DonationsContext.CloseInMemoryConnection();
            }
        }