CreateEnvironmentCommandHandler_Handle_ShouldThrowExceptionIfEnvironmentAlreadyExistsInApplication()
        {
            var applicationId     = Guid.Parse("346AD95F-3B37-453A-B6E1-07F625BCB0CC");
            var createEnvironment = new CreateEnvironmentDto
            {
                ApplicationId = applicationId,
                Name          = "Prod",
                Description   = "Description"
            };
            var application = new Domain.Entities.Application
            {
                Id   = applicationId,
                Name = "Application",
            };

            Context.Applications.Add(application);
            Context.Environments.Add(new Domain.Entities.Environment
            {
                Id            = Guid.NewGuid(),
                Application   = application,
                ApplicationId = applicationId,
                Name          = "Prod",
                IsActive      = true
            });
            await Context.SaveChangesAsync();

            var command = new CreateEnvironmentCommand(createEnvironment);
            await Assert.ThrowsAsync <RecordAlreadyExistsException>(() =>
                                                                    _createEnvironmentsCommandHandler.Handle(command, CancellationToken.None));
        }
        CreateEnvironmentCommandHandler_Handle_ShouldAddNewEnvironmentInApplication()
        {
            var applicationId     = Guid.Parse("346AD95F-3B37-453A-B6E1-07F625BCB0CC");
            var createEnvironment = new CreateEnvironmentDto
            {
                ApplicationId = applicationId,
                Name          = "Development",
                Description   = "Description"
            };
            var application = new Domain.Entities.Application
            {
                Id   = applicationId,
                Name = "Application",
            };

            Context.Applications.Add(application);
            Context.Environments.Add(new Domain.Entities.Environment
            {
                Id            = Guid.NewGuid(),
                ApplicationId = applicationId,
                Name          = "Prod",
                IsActive      = true
            });
            await Context.SaveChangesAsync();

            var command = new CreateEnvironmentCommand(createEnvironment);
            await _createEnvironmentsCommandHandler.Handle(command, CancellationToken.None);

            var actualEnvironmentCount = await
                                         Context.Environments.Where(env => env.ApplicationId == applicationId)
                                         ?.CountAsync(CancellationToken.None);

            Assert.Equal(2, actualEnvironmentCount);
        }
Exemplo n.º 3
0
        public async Task It_should_create()
        {
            CreateEnvironmentDto testEnv = new CreateEnvironmentDto()
            {
                Code = Guid.NewGuid().ToString(), Name = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString()
            };

            using TestServer server = TestServer(UserRole.Administrator);
            using HttpClient client = server.CreateHttpClient();
            HttpResponseMessage result = await client.PostAsync($"features/application/{DataSeed.Application1.Code}/environment/", testEnv.Serialize());

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
            Log.WriteLine(result.Content.ReadAsStringAsync().Result);
            EnvironmentDto env = result.Deserialize <EnvironmentDto>();

            Assert.Equal(testEnv.Code, env.Code);
            Assert.Equal(testEnv.Description, env.Description);
            Assert.Equal(testEnv.Name, env.Name);

            result = await client.GetAsync($"features/application/{DataSeed.Application1.Code}/environment/{testEnv.Code}");

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
            env = result.Deserialize <EnvironmentDto>();
            Assert.Equal(testEnv.Code, env.Code);
            Assert.Equal(testEnv.Description, env.Description);
            Assert.Equal(testEnv.Name, env.Name);
        }
        public async Task CreateEnvironmentCommandHandler_Handle_ShouldThrowExceptionIfApplicationNotExists()
        {
            var createEnvironment = new CreateEnvironmentDto
            {
                ApplicationId = Guid.NewGuid(),
                Name          = "Name",
                Description   = "Description"
            };

            var command = new CreateEnvironmentCommand(createEnvironment);
            await Assert.ThrowsAsync <SpiderException>(() =>
                                                       _createEnvironmentsCommandHandler.Handle(command, CancellationToken.None));
        }
Exemplo n.º 5
0
        public async Task It_should_forbiden_create()
        {
            CreateEnvironmentDto testEnv = new CreateEnvironmentDto()
            {
                Code = Guid.NewGuid().ToString(), Name = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString()
            };

            using TestServer server = TestServer(UserRole.Administrator);
            using HttpClient client = server.CreateHttpClient();
            HttpResponseMessage result = await client.PostAsync($"features/application/{DataSeed.Application2.Code}/environment/", testEnv.Serialize());

            Assert.Equal(HttpStatusCode.Forbidden, result.StatusCode);

            result = await client.GetAsync($"features/application/{DataSeed.Application2.Code}/environment/{testEnv.Code}");

            Assert.Equal(HttpStatusCode.NotFound, result.StatusCode);
        }
Exemplo n.º 6
0
 public CreateEnvironmentCommand(CreateEnvironmentDto request)
 {
     Request = request;
 }
Exemplo n.º 7
0
 public async Task Create(CreateEnvironmentDto environment)
 {
     await Mediator.Send(new CreateEnvironmentCommand(environment));
 }
Exemplo n.º 8
0
        public async Task <IActionResult> CreateEnvironment(string appCode, [FromBody] CreateEnvironmentDto environment)
        {
            UsersEnvironments result = await _mediator.Send(new CreateEnvironmentsCommand(appCode, environment.Name, environment.Code, environment.Description));

            return(Ok(new EnvironmentDto(result)));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Post([FromBody] CreateEnvironmentDto environment)
        {
            await _environmentService.Create(environment);

            return(Ok("Environment added successfully."));
        }