public async Task ValidModel_CreateCampaignAndReturnToList()
        {
            // Arrange
            Campaign savedCamp = null;

            _mockRepo.Setup(repo => repo.CreateAsync(It.IsAny <Campaign>()))
            .ReturnsAsync(true)
            .Callback <Campaign>(x => savedCamp = x);

            var newCamp = new CampaignVM
            {
                CampaignName = "test"
            };

            // Act
            var result = await _sut.Create(newCamp);

            // Assert
            _mockRepo.Verify(x => x.CreateAsync(It.IsAny <Campaign>()), Times.Once);

            Assert.Equal(newCamp.CampaignName, savedCamp.CampaignName);

            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", redirectToActionResult.ActionName);
        }
Exemplo n.º 2
0
        public ActionResult Create(CampaignVM campaign)
        {
            try
            {
                ViewBag.CampaignTypes = GetCampaignTypes();
                if (ModelState.IsValid)
                {
                    ViewBag.CampaignTypes = GetCampaignTypes();
                    campaign.CreatedBy    = User.Identity.Name;
                    var campaignModule = new CampaignModule();
                    var report         = campaignModule.ValidateCampaign(campaign);
                    TempData["CampaignReport"] = report;
                    return(View("Report", report.Validations));
                }
                ViewBag.Message = "Error in input. Please correct the errors";

                return(View(campaign));
            }
            catch (Exception ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
                ViewBag.Message = "Cannot create campaign";
                return(View(campaign));
            }
        }
Exemplo n.º 3
0
        public ActionResult Create(int id = 0)
        {
            CampaignVM campaign = (id == 0) ? new CampaignVM() : new CampaignModule().GetCampaign(id);

            ViewBag.CampaignTypes = GetCampaignTypes();
            return(View(campaign));
        }
Exemplo n.º 4
0
        public async Task NullModel_ReturnBadRequest()
        {
            // Arrange
            CampaignVM camp = null;

            // Act
            var result = await _sut.Edit(camp);

            // Assert
            _mockRepo.Verify(repo => repo.UpdateAsync(It.IsAny <Campaign>()), Times.Never);
            var redirectToPageResult = Assert.IsType <RedirectToPageResult>(result);

            Assert.Equal("/BadRequest", redirectToPageResult.PageName);
        }
Exemplo n.º 5
0
 public EP.BulkMessage.Service.Entity.Campaign GetCampaignFromVM(CampaignVM viewModel)
 {
     return(new Service.Entity.Campaign
     {
         ContentTemplate = viewModel.Content,
         CreatedBy = viewModel.CreatedBy,
         CreatedDate = DateTime.Now,
         FileName = viewModel.FileName,
         Id = viewModel.Id,
         Name = viewModel.Name,
         StatusDate = viewModel.StatusDate,
         StatusId = viewModel.StatusId,
         SubjectTemplate = viewModel.Subject,
         RecipientField = viewModel.RecipientField,
         TypeId = viewModel.TypeId
     });
 }
        public async Task UnsuccessfulCreation_ReturnInternalServerError()
        {
            // Arrange
            var newCamp = new CampaignVM
            {
                CampaignName = "test"
            };

            _mockRepo.Setup(repo => repo.CreateAsync(It.IsAny <Campaign>()))
            .ReturnsAsync(false);

            // Act
            var result = await _sut.Create(newCamp);

            // Assert
            var redirectToPageResult = Assert.IsType <RedirectToPageResult>(result);

            Assert.Equal("/InternalServerError", redirectToPageResult.PageName);
        }
        public async Task InvalidModel_DoNotCallTheDb()
        {
            // Arrange
            _sut.ModelState.AddModelError("x", "Test Error");

            var newCamp = new CampaignVM();

            // Act
            var result = await _sut.Create(newCamp);

            // Assert
            _mockRepo.Verify(repo => repo.CreateAsync(It.IsAny <Campaign>()), Times.Never);

            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsType <CampaignVM>(viewResult.Model);

            Assert.False(viewResult.ViewData.ModelState.IsValid);
            Assert.Equal(newCamp.CampaignName, model.CampaignName);
        }
Exemplo n.º 8
0
        public CampaignReport ValidateCampaign(CampaignVM campaignVM)
        {
            CampaignValidation validations = new CampaignValidation();
            var fileName = campaignVM.FileName;
            var fields   = GetAllMappingFields(campaignVM.Content);

            fields.AddRange(GetAllMappingFields(campaignVM.RecipientField));
            if (campaignVM.TypeId == (int)CampaignType.Email)
            {
                fields.AddRange(GetAllMappingFields(campaignVM.Subject));
            }

            var excelRows = GetExcelMappings(fileName);

            ValidateExcelForFields(ref validations, fields, excelRows);

            var validRows = new List <Row>();

            if (validations.IsValid)
            {
                int rowCount = 2;
                foreach (var row in excelRows)
                {
                    var recepient = row[GetAllMappingFields(campaignVM.RecipientField)[0]];
                    if (validations.Validate(recepient, (CampaignType)campaignVM.TypeId, rowCount))
                    {
                        validRows.Add(row);
                    }
                    rowCount += 1;
                }
            }
            validations.TotalRecordCount = excelRows.Count();
            var report = new CampaignReport
            {
                Campaign    = campaignVM,
                ExcelRows   = validRows,
                Validations = validations
            };

            return(report);
        }
Exemplo n.º 9
0
        public EditTests()
        {
            _mockRepo   = new Mock <ICampaignRepository>();
            _mockLogger = new Mock <ILogger <CampaignRepository> >();
            var mapperConfig = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new Maps());
            });

            _mapper    = mapperConfig.CreateMapper();
            _sut       = new CampaignsController(_mockRepo.Object, _mockLogger.Object, _mapper);
            _savedCamp = new Campaign
            {
                CampaignId   = 1,
                CampaignName = "test"
            };
            _updatedCamp = new CampaignVM
            {
                CampaignId   = 1,
                CampaignName = "changed"
            };
        }
Exemplo n.º 10
0
        public CampaignVM CampaignToCampaignVM(Campaign c)
        {
            var vm = new CampaignVM
            {
                Id                      = c.Id,
                Status                  = c.Status,
                CategoryId              = c.CampaignCategoryId,
                Category                = c.Category == null ? null : c.Category.Name,
                TotalDays               = c.TotalDays,
                Tags                    = c.TagMaps.Select(tm => tm.CampaignTagName).ToList(),
                CityId                  = (c.Location == null) ? (int?)null : c.Location.CityId,
                City                    = (c.Location == null || c.Location.City == null) ? null : c.Location.City.Name,
                Province                = (c.Location == null || c.Location.City == null) ? null : c.Location.City.ProvinceName,
                ProjectStageId          = c.ProjectStageId,
                ProjectStage            = c.ProjectStage == null ? null : c.ProjectStage.Name,
                Tagline                 = c.Tagline,
                TargetFund              = c.TargetFund,
                Thumbnail               = c.ThumbnailFullPath,
                Title                   = c.Title,
                VerificationDescription = c.VerificationDescription,
                VerifiedByOrg           = c.VerifiedByOrg,
                NBacked                 = c.NBacked,
                CollectedFund           = c.CollectedFund,
                CollectedFundPercent    = c.CollectedFundPercent,
                TotalSecondsLeft        = c.TotalSecondsLeft
            };

            try
            {
                vm.StoryElements = JsonConvert.DeserializeObject <string[]>(c.Story);
            }
            catch
            {
                vm.StoryElements = new string[] { c.Story ?? "" };
            }

            return(vm);
        }