Esempio n. 1
0
        public async Task GetCharityByUrlRequest_Handle_Returns_Null()
        {
            CharityContext.OpenInMemoryConnection();
            try
            {
                //Arrange

                using (var context = CharityContext.GetInMemoryContext())
                {
                    var charity = new Charity
                    {
                        CharityKey    = Guid.NewGuid(),
                        Name          = "testNameCharity",
                        OwnerUserName = "******",
                        Email         = "*****@*****.**",
                        Category      = Core.Enums.Category.None,
                        KVKNumber     = "",
                        IBAN          = "0-IBAN",
                        CoverImage    = "",
                        Slogan        = "Test",
                        Url           = "test",
                        IsApproved    = true
                    };

                    context.Add(charity);
                    context.SaveChanges();
                }

                var request = new GetCharityByUrlRequest
                {
                    Url = "WeirdUrl"
                };

                GetCharityByUrlResponse response;

                //Act
                using (var context = CharityContext.GetInMemoryContext())
                {
                    var handler = new GetCharityByUrlRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile()));
                    response = await handler.Handle(request);
                }

                //Assert
                Assert.IsFalse(response.IsSuccess);
            }
            finally
            {
                CharityContext.CloseInMemoryConnection();
            }
        }
Esempio n. 2
0
        public async Task GetCharityByUrlRequest_Handle_Returns_Charity()
        {
            CharityContext.OpenInMemoryConnection();
            try
            {
                //Arrange
                using (var context = CharityContext.GetInMemoryContext())
                {
                    var charity = new Charity
                    {
                        CharityKey    = Guid.NewGuid(),
                        Name          = "testNameCharity",
                        OwnerUserName = "******",
                        Email         = "*****@*****.**",
                        Category      = Core.Enums.Category.None,
                        KVKNumber     = "",
                        IBAN          = "0-IBAN",
                        CoverImage    = "",
                        Slogan        = "Test",
                        Url           = "test",
                        IsApproved    = true
                    };

                    context.Add(charity);
                    context.SaveChanges();
                }
                var request = new GetCharityByUrlRequest()
                {
                    Url = "TEST"
                };

                GetCharityByUrlResponse response;

                //Act
                using (var context = CharityContext.GetInMemoryContext())
                {
                    var handler = new GetCharityByUrlRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile()));
                    response = await handler.Handle(request);
                }

                //Assert
                using (var context = CharityContext.GetInMemoryContext())
                {
                    Assert.AreEqual(response.Charity.Url.ToLower(), request.Url.ToLower());
                    Assert.AreEqual(response.Charity.CharityKey, context.Charities.Single().CharityKey);
                    Assert.AreEqual(response.Charity.Name, context.Charities.Single().Name);
                    Assert.AreEqual(response.Charity.OwnerUserName, context.Charities.Single().OwnerUserName);
                    Assert.AreEqual(response.Charity.Email, context.Charities.Single().Email);
                    Assert.AreEqual(response.Charity.Category, context.Charities.Single().Category);
                    Assert.AreEqual(response.Charity.KVKNumber, context.Charities.Single().KVKNumber);
                    Assert.AreEqual(response.Charity.IBAN, context.Charities.Single().IBAN);
                    Assert.AreEqual(response.Charity.CoverImage, context.Charities.Single().CoverImage);
                    Assert.AreEqual(response.Charity.Slogan, context.Charities.Single().Slogan);
                    Assert.IsTrue(response.IsSuccess);
                }
            }
            finally
            {
                CharityContext.CloseInMemoryConnection();
            }
        }