コード例 #1
0
ファイル: CampaignController.cs プロジェクト: Luse/EmailTimer
        public async Task <ActionResult> Post(string campaignName, CancellationToken cancellationToken)
        {
            if (campaignName == null)
            {
                return(BadRequest());
            }
            var userEmail = HttpContext.User.FindFirst(ClaimTypes.Email)?.Value;
            await _service.CreateNewCampaign(campaignName, userEmail, cancellationToken);

            var list = await _service.GetAllCampaignsForUser(userEmail, cancellationToken);

            return(Ok(list));
        }
コード例 #2
0
        public async void GivenCreateNewCampaign_whenCreatingANewCampaign_ThenCampaignIsCreated()
        {
            var testCampaign = Campaign.CreateNewCampaign("java", "VAB", new DateTime(2018, 04, 21), new DateTime(2018, 06, 22));

            using (var context = new SwitchFullyIntakeAppContext(CreateNewInMemoryDatabase()))
            {
                var log     = new LoggerManager();
                var repo    = new CampaignRepository(context);
                var service = new CampaignService(repo, log);
                var result  = await service.CreateNewCampaign(testCampaign);

                Assert.True(context.Campaigns.SingleOrDefaultAsync(r => r.CampaignId == testCampaign.CampaignId) != null);
            }
        }
コード例 #3
0
        public async void GivenCreateNewCampaignUnhappyPath_whenCreatingANewCampaignWhenNotallFieldsAreFilledIn_ThenReturnNull()
        {
            var testCampaign = new Campaign(Guid.NewGuid(), "", "VAB", new DateTime(2018, 04, 21), new DateTime(2018, 06, 22));

            testCampaign = null;
            using (var context = new SwitchFullyIntakeAppContext(CreateNewInMemoryDatabase()))
            {
                var log     = new LoggerManager();
                var repo    = new CampaignRepository(context);
                var service = new CampaignService(repo, log);

                var exc = await Assert.ThrowsAsync <NullReferenceException>(async() => await service.CreateNewCampaign(testCampaign));
            }
        }