public async Task GivenNewCampaignJsonWithoutName_WhenCreatingNewCampaign_ThenReturnBadRequest()
        {
            var server = new TestServer(new WebHostBuilder()
                                        .UseStartup <TestStartup>()
                                        .UseConfiguration(new ConfigurationBuilder()
                                                          .AddUserSecrets("ecafb124-3b88-4041-ac3d-6bf9172b7efa")
                                                          .AddEnvironmentVariables()
                                                          .Build()));

            using (server)
            {
                var client = await InitClient(server);


                var newDTOCreated = new CreateCampaignDto()
                {
                    // Name = "testCampaign",
                    Client         = "testClient",
                    ClassStartDate = DateTime.Today.AddDays(5),
                    StartDate      = DateTime.Today.AddDays(5),
                    Comment        = "testComment"
                };

                var content       = JsonConvert.SerializeObject(newDTOCreated);
                var stringContent = new StringContent(content, Encoding.UTF8, "application/json");

                var response = await client.PostAsync("api/campaigns", stringContent);

                var responseString = await response.Content.ReadAsStringAsync();

                Assert.Equal("BadRequest", response.StatusCode.ToString());
            }
        }
        public async Task GivenHappyPath_WhenGetAllCampaigns_ThenCampaignsAreReturned()
        {
            var server = new TestServer(new WebHostBuilder()
                                        .UseStartup <TestStartup>()
                                        .UseConfiguration(new ConfigurationBuilder()
                                                          .AddUserSecrets("ecafb124-3b88-4041-ac3d-6bf9172b7efa")
                                                          .AddEnvironmentVariables()
                                                          .Build()));

            using (server)
            {
                var client = await InitClient(server);

                var newDTOCreated = new CreateCampaignDto()
                {
                    Name           = "testCampaign",
                    Client         = "testClient",
                    ClassStartDate = DateTime.Today.AddDays(5),
                    StartDate      = DateTime.Today.AddDays(5),
                    Comment        = "testComment"
                };

                var content       = JsonConvert.SerializeObject(newDTOCreated);
                var stringContent = new StringContent(content, Encoding.UTF8, "application/json");

                var response = await client.GetAsync("api/campaigns");

                response.EnsureSuccessStatusCode();

                Assert.Equal("OK", response.StatusCode.ToString());
            }
        }
Ejemplo n.º 3
0
        public ActionResult <CampaignDto> CreateCampaign([FromBody] CreateCampaignDto createCampaignDto)
        {
            var newCampaign = _campaignMapper.ToDto(
                _campaignService.AddCampaign(
                    _campaignMapper.ToNewDomain(createCampaignDto)));

            return(Created($"api/campaign/{newCampaign.Id}", newCampaign));
        }
Ejemplo n.º 4
0
        private async Task <CreateJobApplicationDto> PrepareNewJobApplicationTest(HttpClient client)
        {
            var newDTOCreatedCandidate = new CandidateDto()
            {
                FirstName      = "Peter",
                LastName       = "Parker",
                Email          = "*****@*****.**",
                PhoneNumber    = "0470000000",
                GitHubUsername = "******",
                LinkedIn       = "peterparker"
            };

            var contentCandidate       = JsonConvert.SerializeObject(newDTOCreatedCandidate);
            var stringContentCandidate = new StringContent(contentCandidate, Encoding.UTF8, "application/json");

            var responseCandidate = await client.PostAsync("api/Candidates", stringContentCandidate);

            var responseStringCandidate = await responseCandidate.Content.ReadAsStringAsync();

            var createdCandidate = JsonConvert.DeserializeObject <CandidateDto>(responseStringCandidate);

            var newDTOCreatedCampaign = new CreateCampaignDto()
            {
                Name           = "testCampaign",
                Client         = "testClient",
                ClassStartDate = DateTime.Today.AddDays(6),
                StartDate      = DateTime.Today.AddDays(5),
                Comment        = "testComment"
            };

            var contentCampaign       = JsonConvert.SerializeObject(newDTOCreatedCampaign);
            var stringContentCampaign = new StringContent(contentCampaign, Encoding.UTF8, "application/json");
            var responseCampaign      = await client.PostAsync("api/campaigns", stringContentCampaign);

            var responseStringCampaign = await responseCampaign.Content.ReadAsStringAsync();

            var createdCampaign = JsonConvert.DeserializeObject <CampaignDto>(responseStringCampaign);

            var newJobApplicationCreatedDto = new CreateJobApplicationDto(
                createdCandidate.Id,
                createdCampaign.Id
                );

            return(newJobApplicationCreatedDto);
        }
        public void GivenACreatedCampaignDto_WhenToNewDomain_ThenReturnCampaignObjectWithIdGuidAndStatusActive()
        {
            //given
            var newDTO = new CreateCampaignDto()
            {
                Name = "testCampaign",
                Client = "testClient",
                ClassStartDate = DateTime.Today.AddDays(5),
                StartDate = DateTime.Today.AddDays(5),
                Comment = "testComment"
            };

            var campaignMapper = new CampaignMapper();

            //when
            var newDomain = campaignMapper.ToNewDomain(newDTO);

            //then
            Assert.IsType<Guid>(newDomain.Id);
            Assert.Equal(CampaignStatus.Active, newDomain.Status);
        }