Esempio n. 1
0
        public async Task <UserDto> Post(UserDtoCreate user)
        {
            var obj = _mapper.Map <UserEntity>(user);

            var result = await _repository.InsertAsync(obj);

            return(_mapper.Map <UserDto>(result));
        }
Esempio n. 2
0
        public async Task <UserDtoCreateResult> Post(UserDtoCreate user)
        {
            var model  = _mapper.Map <UserModel>(user);
            var entity = _mapper.Map <UserEntity>(model);
            var result = await _repository.InsertAsync(entity);

            return(_mapper.Map <UserDtoCreateResult>(result));
        }
Esempio n. 3
0
        public async Task <UserDtoCreateResult> Post(UserDtoCreate userDto)
        {
            UserModel  userModel  = _mapper.Map <UserModel>(userDto);
            UserEntity userEntity = _mapper.Map <UserEntity>(userModel);
            UserEntity result     = await _repository.InsertAsync(userEntity);

            return(_mapper.Map <UserDtoCreateResult>(result));
        }
        public async Task <UserDtoCreateResult> Post(UserDtoCreate user)
        {
            var model  = _mapper.Map <UserModel>(user); //não precisaria mas o DDD se for necessário alguma valiação precisa...
            var entity = _mapper.Map <UserEntity>(model);
            var result = await _repository.InsertAsync(entity);

            return(_mapper.Map <UserDtoCreateResult>(result));
        }
Esempio n. 5
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
            };
        }
Esempio n. 6
0
        public async Task <UserDtoCreateResult> Post(UserDtoCreate user)
        {
            var entity = _mapper.Map <UserEntity>(user);

            entity.Email = entity.Email.ToLower();
            var result = await _repository.InsertAsync(entity);

            return(_mapper.Map <UserDtoCreateResult>(result));
        }
Esempio n. 7
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
            };
        }
Esempio n. 8
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
            };
        }
Esempio n. 9
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
            };
        }
Esempio n. 10
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
            };
        }
Esempio n. 11
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 async Task <UserDtoCreateResult> Post(UserDtoCreate item)
        {
            if (item.Name == "Teste")
            {
                return(null);
            }

            var model  = _mapper.Map <UserModel>(item);
            var entity = _mapper.Map <UserEntity>(model);
            var result = await _repository.InsertAsync(entity);

            return(_mapper.Map <UserDtoCreateResult>(result));
        }
Esempio n. 13
0
        public async Task CreateTest()
        {
            var serviceMock = new Mock <IUserService>();
            var name        = Faker.Name.FullName();
            var email       = Faker.Internet.Email();

            serviceMock.Setup(m => m.Post(It.IsAny <UserDtoCreate>())).ReturnsAsync(
                new UserDtoCreateResult
            {
                Id       = Guid.NewGuid(),
                Name     = name,
                Email    = email,
                CreateAt = DateTime.UtcNow
            }
                );

            _controller = new UsersController(serviceMock.Object);

            Mock <IUrlHelper> url = new Mock <IUrlHelper>();

            url.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("http://localhost:5000");
            _controller.Url = url.Object;

            var userDtoCreate = new UserDtoCreate
            {
                Name  = name,
                Email = email
            };

            var result = await _controller.Post(userDtoCreate);

            var resultValue = ((CreatedResult)result).Value as UserDtoCreateResult;

            //Assert.True(result is CreatedResult);
            //Assert.NotNull(resultValue);
            //Assert.Equal(userDtoCreate.Name, resultValue.Name);
            //Assert.Equal(userDtoCreate.Email, resultValue.Email);

            result.Should().BeOfType <CreatedResult>();
            resultValue.Name.Should().Equals(userDtoCreate.Name);
            resultValue.Email.Should().Equals(userDtoCreate.Email);
        }
        public async Task <ActionResult> Post([FromBody] UserDtoCreate user)
        {
            try
            {
                var 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(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failed {ex.Message}"));
            }
        }
Esempio n. 15
0
        public async Task E_Possivel_Invocar_a_Controller_Create()
        {
            var serviceMock = new Mock <IUserService>();
            var nome        = Faker.Name.FullName();
            var email       = Faker.Internet.Email();

            serviceMock.Setup(m => m.Post(It.IsAny <UserDtoCreate>())).ReturnsAsync(
                new UserDtoCreateResult
            {
                Id       = Guid.NewGuid(),
                Nome     = nome,
                Email    = email,
                CreateAt = DateTime.UtcNow
            }

                );
            _controller = new UserController(serviceMock.Object);
            //_controller.ModelState.AddModelError("Nome","O campo é obrigatório !");

            Mock <IUrlHelper> url = new Mock <IUrlHelper>();

            url.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <Object>())).Returns("localhost:3000/teste");
            _controller.Url = url.Object;

            var userDtoCreate = new UserDtoCreate
            {
                Nome  = nome,
                Email = email
            };

            var result = await _controller.Post(userDtoCreate);

            Assert.True(result is CreatedResult);

            var resultValue = ((CreatedResult)result).Value as UserDtoCreateResult;

            Assert.NotNull(resultValue);
            Assert.Equal(userDtoCreate.Nome, resultValue.Nome);
            Assert.Equal(userDtoCreate.Email, resultValue.Email);
        }
Esempio n. 16
0
        public async Task E_Possivel_Realizar_Crud_Usuario()
        {
            await AdicionarToken();

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

            var userDto = new UserDtoCreate()
            {
                Nome  = _nome,
                Email = _email
            };

            //Post
            var response = await PostJasonAsync(userDto, $"{hostAPI}user", client);

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

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

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

            //GetAll
            response = await client.GetAsync($"{hostAPI}user");

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

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

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

            Assert.NotNull(listJson);
            Assert.True(listJson.Count() > 0);
            Assert.True(listJson.Where(l => l.Id == registroPost.Id).Count() == 1);
        }
        public async Task E_Possível_Invocar_A_Controller_Create()
        {
            var serviceMock = new Mock <IUserService>();
            var nome        = Faker.Name.FullName();
            var email       = Faker.Internet.Email();
            var password    = Guid.NewGuid();

            serviceMock.Setup(m => m.Post(It.IsAny <UserDtoCreate>())).ReturnsAsync(
                new UserDtoCreateResult
            {
                Id       = Guid.NewGuid(),
                Email    = email,
                Name     = nome,
                CreateAt = DateTime.UtcNow,
            }
                );

            _controller = new UsersController(serviceMock.Object);
            Mock <IUrlHelper> url = new Mock <IUrlHelper>();

            url.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("http://localhost:5000");
            _controller.Url = url.Object;
            var userDtoCreate = new UserDtoCreate
            {
                Email    = email,
                Name     = nome,
                Password = password.ToString()
            };

            var result = await _controller.Post(userDtoCreate);

            Assert.True(result is CreatedResult);

            var resultvalue = ((CreatedResult)result).Value as UserDtoCreateResult;

            Assert.NotNull(resultvalue);
            Assert.Equal(userDtoCreate.Name, resultvalue.Name);
            Assert.Equal(userDtoCreate.Email, resultvalue.Email);
        }
        public async Task <ActionResult> Post([FromBody] UserDtoCreate user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try {
                var 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_Invocar_a_UsersController_Create_Retornando_OK()
        {
            var serviceMock = new Mock <IUserService>();
            var name        = Name.FullName();
            var email       = Internet.Email();

            serviceMock.Setup(m => m.Post(It.IsAny <UserDtoCreate>())).ReturnsAsync(
                new UserDtoCreateResult
            {
                Id       = Guid.NewGuid(),
                Name     = name,
                Email    = email,
                CreateAt = DateTime.UtcNow
            });

            _controller = new UsersController(serviceMock.Object);

            Mock <IUrlHelper> url = new Mock <IUrlHelper>();

            url.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <Object>())).Returns("http://localhost:5000");
            _controller.Url = url.Object;

            var userDtoCreated = new UserDtoCreate
            {
                Name  = name,
                Email = email,
            };

            var result = await _controller.Post(userDtoCreated);

            Assert.True(result is CreatedResult);

            var resultvalue = ((CreatedResult)result).Value as UserDtoCreateResult;

            Assert.NotNull(resultvalue);
            Assert.Equal(userDtoCreated.Name, resultvalue.Name);
            Assert.Equal(userDtoCreated.Email, resultvalue.Email);
        }
Esempio n. 20
0
        public async Task Execute_Get()
        {
            var serviceMock   = new Mock <IUserService>();
            var nome          = Faker.Name.FullName();
            var email         = Faker.Internet.Email();
            var userDtoCreate = new UserDtoCreate();

            serviceMock.Setup(m => m.Get(It.IsAny <Guid>())).ReturnsAsync(new UserDto
            {
                Id       = Guid.NewGuid(),
                Name     = nome,
                Email    = email,
                CreateAt = DateTime.Now
            });

            _controller = new UsersController(serviceMock.Object);
            var result = await _controller.Get(Guid.NewGuid());

            var resultValue = ((OkObjectResult)result).Value as UserDto;

            Assert.True(result is OkObjectResult);
            Assert.Equal(nome, resultValue.Name);
        }
Esempio n. 21
0
        public async Task <ActionResult <UserDtoCreateResult> > PostUser([FromBody] UserDtoCreate userDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var result = await _service.Post(userDto);

                if (result != null)
                {
                    return(CreatedAtAction("GetUser", new { id = result.Id }, userDto));
                }

                return(BadRequest());
            }
            catch (ArgumentException ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex));
            }
        }
Esempio n. 22
0
        public async Task It_Is_Possible_To_Invoke_The_Controller_Create()
        {
            var serviceMock = new Mock <IUserService>();
            var name        = Faker.Name.FullName();
            var email       = Faker.Internet.Email();

            serviceMock.Setup(s => s.Post(It.IsAny <UserDtoCreate>())).ReturnsAsync(
                new UserDtoCreateResult
            {
                Id        = Guid.NewGuid(),
                Name      = name,
                Email     = email,
                CreatedAt = DateTime.Now
            });

            _controller = new UsersController(serviceMock.Object);
            Mock <IUrlHelper> url = new Mock <IUrlHelper>();

            url.Setup(s => s.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("http://localhost:5000");
            _controller.Url = url.Object;

            var userDtoCreate = new UserDtoCreate
            {
                Name  = name,
                Email = email
            };

            var result = await _controller.Post(userDtoCreate);

            Assert.True(result is CreatedResult);

            var resultValue = ((CreatedResult)result).Value as UserDtoCreateResult;

            Assert.NotNull(resultValue);
            Assert.Equal(userDtoCreate.Name, resultValue.Name);
            Assert.Equal(userDtoCreate.Email, resultValue.Email);
        }
Esempio n. 23
0
        public async Task It_Is_Possible_To_Run_User_Crud()
        {
            await AddToken();

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

            var userDtoCreate = new UserDtoCreate
            {
                Name  = _name,
                Email = _email
            };

            // Post
            var response = await PostJsonAsync(userDtoCreate, $"{HostApi}/users", Client);

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

            var userDtoCreateResult = JsonConvert.DeserializeObject <UserDtoCreateResult>(responseString);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.Equal(_name, userDtoCreateResult.Name);
            Assert.Equal(_email, userDtoCreateResult.Email);
            Assert.False(userDtoCreateResult.Id == default);

            // Get All
            response = await Client.GetAsync($"{HostApi}/users");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            responseString = await response.Content.ReadAsStringAsync();

            var userDtos = JsonConvert.DeserializeObject <IEnumerable <UserDto> >(responseString);

            Assert.NotNull(userDtos);
            Assert.True(userDtos.Count() > 0);
            Assert.True(userDtos.Where(x => x.Id == userDtoCreateResult.Id).Count() == 1);

            // Put
            var userDtoUpdate = new UserDtoUpdate
            {
                Id    = userDtoCreateResult.Id,
                Name  = Faker.Name.FullName(),
                Email = Faker.Internet.Email()
            };
            var content = new StringContent(JsonConvert.SerializeObject(userDtoUpdate), Encoding.UTF8, "application/json");

            response = await Client.PutAsync($"{HostApi}/users", content);

            responseString = await response.Content.ReadAsStringAsync();

            var userDtoUpdateResult = JsonConvert.DeserializeObject <UserDtoUpdateResult>(responseString);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(userDtoCreateResult.Id, userDtoUpdateResult.Id);
            Assert.NotEqual(userDtoCreateResult.Name, userDtoUpdateResult.Name);
            Assert.NotEqual(userDtoCreateResult.Email, userDtoUpdateResult.Email);
            Assert.Equal(userDtoUpdate.Id, userDtoUpdateResult.Id);
            Assert.Equal(userDtoUpdate.Name, userDtoUpdateResult.Name);
            Assert.Equal(userDtoUpdate.Email, userDtoUpdateResult.Email);

            // Get
            response = await Client.GetAsync($"{HostApi}/users/{userDtoUpdateResult.Id}");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            responseString = await response.Content.ReadAsStringAsync();

            var userDto = JsonConvert.DeserializeObject <UserDto>(responseString);

            Assert.NotNull(userDto);
            Assert.Equal(userDtoUpdateResult.Name, userDto.Name);
            Assert.Equal(userDtoUpdateResult.Email, userDto.Email);

            // Delete
            response = await Client.DeleteAsync($"{HostApi}/users/{userDto.Id}");

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

            // Get after Delete
            response = await Client.GetAsync($"{HostApi}/users/{userDto.Id}");

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
        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
            var response = await PostJsonAsync(userDto, $"{hostApi}users/post", client);

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

            var 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/GetAll");

            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);

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

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

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

            jsonResult = await response.Content.ReadAsStringAsync();

            var registroAtualizado = JsonConvert.DeserializeObject <UserDtoUpdateResult>(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/GetWithId/{registroAtualizado.Id}");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            jsonResult = await response.Content.ReadAsStringAsync();

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

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

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

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

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

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
        }
        public async Task User_CRUD()
        {
            await AdicionarToken();

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

            //POST

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

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

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

            var result = JsonConvert.DeserializeObject <UserDtoCreateResult>(postResult);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.Equal(_name, result.Name);
            Assert.Equal(_email, result.Email);

            Assert.False(result.Id == default(Guid));

            //PUT

            var updateUserDto = new UserDtoUpdate
            {
                Id    = result.Id,
                Name  = Faker.Name.FullName(),
                Email = Faker.Internet.Email()
            };

            response = await client.PutAsync($"{hostApi}users/" + result.Id, new StringContent(JsonConvert.SerializeObject(updateUserDto), Encoding.UTF8, "application/json"));

            postResult = await response.Content.ReadAsStringAsync();

            var resultPUT = JsonConvert.DeserializeObject <UserDtoUpdateResult>(postResult);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(result.Id, resultPUT.Id);
            Assert.False(resultPUT.Name == result.Name);

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

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            postResult = await response.Content.ReadAsStringAsync();

            var resultGet = JsonConvert.DeserializeObject <UserDto>(postResult);

            Assert.Equal(result.Id, resultGet.Id);
            Assert.Equal(resultPUT.Name, resultGet.Name);

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

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Esempio n. 26
0
        public UsuarioTestes()
        {
            IdUsuario            = Faker.RandomNumber.Next();
            NomeUsuario          = Faker.Name.FullName();
            EmailUsuario         = Faker.Internet.Email();
            RoleUsuario          = "ADM";
            SenhaUsuario         = Faker.Internet.UserName();
            NomeUsuarioAlterado  = Faker.Name.FullName();
            EmailUsuarioAlterado = Faker.Internet.Email();
            RoleUsuarioAlterado  = "Basic";
            SenhaUsuarioAlterado = Faker.Internet.UserName();

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

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

            userDtoCreate = new UserDtoCreate
            {
                Name  = NomeUsuario,
                Email = EmailUsuario,
                Senha = SenhaUsuario,
                Role  = RoleUsuario
            };

            userDtoCreateReult = new UserDtoCreateReult
            {
                Id    = IdUsuario,
                Name  = NomeUsuario,
                Email = EmailUsuario,
                Senha = SenhaUsuario,
                Role  = RoleUsuario
            };

            userDtoUpdate = new UserDtoUpdate
            {
                Id    = IdUsuario,
                Name  = NomeUsuario,
                Email = EmailUsuario,
                Senha = SenhaUsuario,
                Role  = RoleUsuario
            };

            userDtoUpdateReult = new UserDtoUpdateReult
            {
                Id    = IdUsuario,
                Name  = NomeUsuario,
                Email = EmailUsuario
            };
        }
Esempio n. 27
0
        public async Task PostIntegrationTest()
        {
            await AddToken();

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

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

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

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

            var registerPost = JsonConvert.DeserializeObject <UserDtoCreateResult>(postResult);

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

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

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

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

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

            Assert.NotNull(listFromJson);
            Assert.True(listFromJson.Count() > 0);
            Assert.True(listFromJson.Where(r => r.Id == registerPost.Id).Count() == 1);

            //Put
            var updateUserDto = new UserDtoUpdate()
            {
                Id    = registerPost.Id,
                Name  = Faker.Name.FullName(),
                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 registerUpdated = JsonConvert.DeserializeObject <UserDtoUpdateResult>(jsonResult);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotEqual(registerPost.Name, registerUpdated.Name);
            Assert.NotEqual(registerPost.Email, registerUpdated.Email);

            //Get Id
            response = await client.GetAsync($"{hostApi}users/{registerUpdated.Id}");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            jsonResult = await response.Content.ReadAsStringAsync();

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

            Assert.NotNull(registerSelected);
            Assert.Equal(registerSelected.Name, registerUpdated.Name);
            Assert.Equal(registerSelected.Email, registerUpdated.Email);

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

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

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

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
        public async Task E_Possivel_Realizar_Crud_Usuario()
        {
            await AdicionarToken();

            _name  = Name.FullName();
            _email = Internet.Email();

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

            //Post
            var response = await PostJsonAsync(userDto, $"{hostApi}/users", Client);

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

            var 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);
//            var fromJson = listaFromJson as UserDto[] ?? listaFromJson.ToArray();
//            Assert.True(fromJson.Any());
//            Assert.True(fromJson.Count(r => r.Id == registroPost.Id) == 1);
//
//            var updateUserDto = new UserDtoUpdate()
//            {
//                Id = registroPost.Id,
//                Name = Name.FullName(),
//                Email = Internet.Email()
//            };
//
//            //PUT
//            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<UserDtoUpdateResult>(jsonResult);
//
//            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
//            Assert.NotEqual(registroPost.Name, registroAtualizado.Name);
//            Assert.NotEqual(registroPost.Email, registroAtualizado.Email);
//
//            //GET Idu
//            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(registroSelecionado.Name, registroAtualizado.Name);
//            Assert.Equal(registroSelecionado.Email, registroAtualizado.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);
//
        }