예제 #1
0
        public async Task <ActionResult> Post([FromBody] UserDtoCreate user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                UserDtoCreateResult result = await _service.Post(user);

                if (result == null)
                {
                    return(BadRequest());
                }

                ResponseBase <UserDtoCreateResult> responseBase = new ResponseBase <UserDtoCreateResult>();
                responseBase.Message = "Usuário criado com sucesso!";
                responseBase.Success = true;
                responseBase.Result  = result;

                return(Created(new Uri(Url.Link("GetUserById", new { id = result.Id })), responseBase));
            }
            catch (ArgumentException e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }
예제 #2
0
        public TestUsers()
        {
            FakerId    = Faker.RandomNumber.Next();
            FakerName  = Faker.Name.FullName();
            FakerEmail = Faker.Internet.Email();

            FakerNameUpdated  = Faker.Name.FullName();
            FakerEmailUpdated = Faker.Internet.Email();

            for (int index = 0; index < 10; index++)
            {
                var dto = new UserDto()
                {
                    Id    = Faker.RandomNumber.Next(),
                    Name  = Faker.Name.FullName(),
                    Email = Faker.Internet.Email()
                };

                FakerUserDtoList.Add(dto);
            }

            FakerUserDto = new UserDto()
            {
                Id    = FakerId,
                Name  = FakerName,
                Email = FakerEmail
            };

            FakerUserDtoCreate = new UserDtoCreate()
            {
                Name  = FakerName,
                Email = FakerEmail
            };

            FakerUserDtoCreateResult = new UserDtoCreateResult()
            {
                Id       = FakerId,
                Name     = FakerName,
                Email    = FakerEmail,
                CreateAt = DateTime.UtcNow
            };

            FakerUserDtoUpdate = new UserDtoUpdate()
            {
                Id    = FakerId,
                Name  = FakerName,
                Email = FakerEmail
            };

            FakerUserDtoUpdateResult = new UserDtoUpdateResult()
            {
                Id       = FakerId,
                Name     = FakerName,
                Email    = FakerEmail,
                UpdateAt = DateTime.UtcNow
            };
        }
예제 #3
0
        public UsuarioTestes()
        {
            IdUsuario            = Guid.NewGuid();
            NomeUsuario          = Faker.Name.FullName();
            EmailUsuario         = Faker.Internet.Email();
            NomeUsuarioAlterado  = Faker.Name.FullName();
            EmailUsuarioAlterado = Faker.Internet.Email();

            for (int i = 0; i < 10; i++)
            {
                var dto = new UserDto()
                {
                    Id    = Guid.NewGuid(),
                    Name  = Faker.Name.FullName(),
                    Email = Faker.Internet.Email()
                };
                listaUserDto.Add(dto);
            }

            userDto = new UserDto
            {
                Id    = IdUsuario,
                Name  = NomeUsuario,
                Email = EmailUsuario
            };

            userDtoCreate = new UserDtoCreate
            {
                Name  = NomeUsuario,
                Email = EmailUsuario
            };


            userDtoCreateResult = new UserDtoCreateResult
            {
                Id       = IdUsuario,
                Name     = NomeUsuario,
                Email    = EmailUsuario,
                CreateAt = DateTime.UtcNow
            };

            userDtoUpdate = new UserDtoUpdate
            {
                Id    = IdUsuario,
                Name  = NomeUsuarioAlterado,
                Email = EmailUsuarioAlterado
            };

            userDtoUpdateResult = new UserDtoUpdateResult
            {
                Id       = IdUsuario,
                Name     = NomeUsuarioAlterado,
                Email    = EmailUsuarioAlterado,
                UpdateAt = DateTime.UtcNow
            };
        }
예제 #4
0
        public UserTest()
        {
            UserId           = Guid.NewGuid();
            UserName         = Faker.Name.FullName();
            UserEmail        = Faker.Internet.Email();
            UserNameChanged  = Faker.Name.FullName();
            UserEmailChanged = Faker.Internet.Email();

            for (int i = 0; i < 10; i++)
            {
                var dto = new UserDto()
                {
                    Id    = Guid.NewGuid(),
                    Nome  = Faker.Name.FullName(),
                    Email = Faker.Internet.Email()
                };

                UserList.Add(dto);
            }

            userDto = new UserDto
            {
                Id   = UserId,
                Nome = UserName
            };

            userDtoCreate = new UserDtoCreate
            {
                Nome  = UserName,
                Email = UserEmail
            };

            userDtoCreateResult = new UserDtoCreateResult
            {
                Id       = UserId,
                Nome     = UserName,
                Email    = UserEmail,
                CreateAt = DateTime.UtcNow
            };

            userDtoUpdate = new UserDtoUpdate
            {
                Id    = UserId,
                Nome  = UserName,
                Email = UserEmail
            };


            userDtoUpdateResult = new UserDtoUpdateResult
            {
                Id       = UserId,
                Nome     = UserName,
                Email    = UserEmail,
                CreateAt = DateTime.UtcNow
            };
        }
예제 #5
0
        public UserTest()
        {
            IdUser          = Guid.NewGuid();
            NomeUser        = Faker.Name.FullName();
            EmailUser       = Faker.Internet.Email();
            NomeUserUpdate  = Faker.Name.FullName();
            EmailUserUpdate = Faker.Internet.Email();

            for (int i = 0; i < 10; i++)
            {
                var Dto = new UserDto()
                {
                    Id    = Guid.NewGuid(),
                    Name  = Faker.Name.FullName(),
                    Email = Faker.Internet.Email(),
                };
                listaDto.Add(Dto);
            }

            userDto = new UserDto
            {
                Id    = IdUser,
                Name  = NomeUser,
                Email = EmailUser
            };

            userDtoCreate = new UserDtoCreate
            {
                Name  = NomeUser,
                Email = EmailUser,
            };

            userDtoCreateResult = new UserDtoCreateResult
            {
                Id       = IdUser,
                Name     = NomeUser,
                Email    = EmailUser,
                CreateAt = DateTime.UtcNow
            };

            userDtoUpdate = new UserDtoUpdate
            {
                Id    = IdUser,
                Name  = NomeUserUpdate,
                Email = EmailUserUpdate,
            };

            userDtoUpdateResult = new UserDtoUpdateResult
            {
                Id       = IdUser,
                Name     = NomeUserUpdate,
                Email    = EmailUserUpdate,
                UpdateAt = DateTime.UtcNow
            };
        }
예제 #6
0
        public UserTestes()
        {
            IdUser         = Guid.NewGuid();
            EmailUser      = Faker.Internet.Email();
            AlterEmailUser = Faker.Internet.Email();
            NameUser       = Faker.Name.FullName();
            AlterNameUser  = Faker.Name.FullName();

            for (int i = 0; i < 10; i++)
            {
                var dto = new UserDto()
                {
                    Id    = Guid.NewGuid(),
                    Name  = Faker.Name.FullName(),
                    Email = Faker.Internet.Email(),
                };
                listUserDto.Add(dto);
            }

            userDto = new UserDto()
            {
                Id    = IdUser,
                Name  = NameUser,
                Email = EmailUser
            };

            userDtoCreate = new UserDtoCreate()
            {
                Name  = NameUser,
                Email = EmailUser
            };


            userDtoCreateResult = new UserDtoCreateResult()
            {
                Id       = IdUser,
                Name     = NameUser,
                Email    = EmailUser,
                CreateAt = DateTime.UtcNow
            };

            userDtoUpdate = new UserDtoUpdate()
            {
                Name  = NameUser,
                Email = EmailUser
            };

            userDtoUpdateResult = new UserDtoUpdateResult()
            {
                Id       = IdUser,
                Name     = NameUser,
                Email    = EmailUser,
                UpdateAt = DateTime.UtcNow
            };
        }
예제 #7
0
        public UserTests()
        {
            UserId           = Guid.NewGuid();
            UserName         = Faker.Name.FullName();
            UserEmail        = Faker.Internet.Email();
            UserNameUpdated  = Faker.Name.FullName();
            UserEmailUpdated = Faker.Internet.Email();

            for (int i = 0; i < 10; i++)
            {
                userDtos.Add(new UserDto()
                {
                    Id    = Guid.NewGuid(),
                    Name  = Faker.Name.FullName(),
                    Email = Faker.Internet.Email()
                });
            }

            userDto = new UserDto()
            {
                Id    = UserId,
                Name  = UserName,
                Email = UserEmail
            };

            userDtoCreate = new UserDtoCreate()
            {
                Name  = UserName,
                Email = UserEmail
            };

            userDtoCreateResult = new UserDtoCreateResult()
            {
                Id        = UserId,
                Name      = UserName,
                Email     = UserEmail,
                CreatedAt = DateTime.Now
            };

            userDtoUpdate = new UserDtoUpdate()
            {
                Id    = UserId,
                Name  = UserNameUpdated,
                Email = UserEmailUpdated
            };

            userDtoUpdateResult = new UserDtoUpdateResult()
            {
                Id        = UserId,
                Name      = UserNameUpdated,
                Email     = UserEmailUpdated,
                UpdatedAt = DateTime.Now
            };
        }
        public UserTests()
        {
            UserId           = Guid.NewGuid();
            Username         = Faker.Name.FullName();
            UserEmail        = Faker.Internet.Email();
            UpdatedUsername  = Faker.Name.FullName();
            UpdatedUserEmail = Faker.Internet.Email();

            for (int i = 0; i < 10; i++)
            {
                var dto = new UserDto()
                {
                    Name  = Faker.Name.FullName(),
                    Email = Faker.Internet.Email()
                };

                listaUserDto.Add(dto);
            }

            userDto = new UserDto
            {
                Name  = Username,
                Email = UserEmail
            };

            userDtoCreateResult = new UserDtoCreateResult
            {
                Name     = Username,
                Email    = UserEmail,
                CreateAt = DateTime.UtcNow
            };

            userDtoUpdateResult = new UserDtoUpdateResult
            {
                Name       = UpdatedUsername,
                Email      = UpdatedUserEmail,
                ModifiedAt = DateTime.UtcNow
            };
        }
        public async Task <ActionResult> Post([FromBody] UserDtoCreate user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                UserDtoCreateResult result = await _service.Post(user);

                if (result != null)
                {
                    return(Created(new Uri(Url.Link("GetWithId", new { id = result.Id })), result));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (ArgumentException ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        public async Task E_Possivel_Realizar_Crud_Usuario()
        {
            await AdicionarToken();

            _name  = Faker.Name.First();
            _email = Faker.Internet.Email();

            var userDto = new UserDtoCreate()
            {
                Name  = _name,
                Email = _email
            };

            // POST
            HttpResponseMessage response = await PostJsonAsync(userDto, $"{hostApi}users", client);

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

            UserDtoCreateResult registroPost = JsonConvert.DeserializeObject <UserDtoCreateResult>(postResult);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.Equal(_name, registroPost.Name);
            Assert.Equal(_email, registroPost.Email);
            Assert.True(registroPost.Id != default(Guid));

            // GET ALL
            response = await client.GetAsync($"{hostApi}users");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

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

            var listaFromJson = JsonConvert.DeserializeObject <IEnumerable <UserDto> >(jsonResult);

            Assert.NotNull(listaFromJson);
            Assert.True(listaFromJson.Count() > 0);
            Assert.True(listaFromJson.Where(r => r.Id == registroPost.Id).Count() == 1);

            // PUT
            var updateUserDto = new UserDtoUpdate()
            {
                Id    = registroPost.Id,
                Name  = Faker.Name.First(),
                Email = Faker.Internet.Email()
            };

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

            response = await client.PutAsync($"{hostApi}users", stringContent);

            jsonResult = await response.Content.ReadAsStringAsync();

            var registroAtualizado = JsonConvert.DeserializeObject <UserDtoCreateResult>(jsonResult);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotEqual(registroPost.Name, registroAtualizado.Name);
            Assert.NotEqual(registroPost.Email, registroAtualizado.Email);

            // GET ID
            response = await client.GetAsync($"{hostApi}users/{registroAtualizado.Id}");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            jsonResult = await response.Content.ReadAsStringAsync();

            var registroSelecionado = JsonConvert.DeserializeObject <UserDto>(jsonResult);

            Assert.NotNull(registroSelecionado);
            Assert.Equal(registroAtualizado.Name, registroSelecionado.Name);
            Assert.Equal(registroAtualizado.Email, registroSelecionado.Email);

            // DELETE
            response = await client.DeleteAsync($"{hostApi}users/{registroSelecionado.Id}");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            // GET ID depois do delete
            response = await client.GetAsync($"{hostApi}users/{registroSelecionado.Id}");

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }