Beispiel #1
0
        public async Task Create_UserDoesExist_CreatedAtRoute()
        {
            // Arrange
            var user  = MockApplicationUsers.Get(8);
            var token = await GetToken(user);

            const string createPath = Routes.TodoRoute;

            _endSystems.SetBearerToken(token);
            var model = new CreateTodoViewModel
            {
                Description = "I am your doctor, when you need, want some coke? Have some weed",
                Due         = new DateTime(2000, 1, 1)
            };
            var body    = JsonStringBuilder.CreateTodoJsonBody(model.Description, model.Due.ToString());
            var content = new StringContent(body);

            // Act
            var createResponse = await _endSystems.Post(createPath, content);

            var location    = createResponse.Headers.Location.ToString();
            var getResponse = await _endSystems.Get(location);

            var dto = JsonStringSerializer.GetTodoDto(getResponse.Body);

            // Assert
            Assert.Equal(HttpStatusCode.Created, createResponse.Code);
            Assert.Equal(HttpStatusCode.OK, getResponse.Code);
            Assert.Equal(model.Description, dto.Description);
            Assert.Equal(model.Due, dto.Due);

            // Tear down
            _endSystems.Dispose();
        }
Beispiel #2
0
        public async Task Create_NoToken_Unauthorized()
        {
            // Arrange
            var          model   = MockCreateTodoViewModel.Get(0);
            var          body    = JsonStringBuilder.CreateTodoJsonBody(model.Description, model.Due.ToString());
            var          content = new StringContent(body);
            const string path    = Routes.TodoRoute;

            // Act
            var response = await _endSystems.Post(path, content);

            // Assert
            Assert.Equal(HttpStatusCode.Unauthorized, response.Code);

            // Tear down
            _endSystems.Dispose();
        }
Beispiel #3
0
        public async Task Create_UserDoesNotExistAnymote_Unauthorized()
        {
            // Arrange
            var user  = MockApplicationUsers.Get(5);
            var admin = MockApplicationUsers.Get(0);

            var userToken = await GetToken(user);

            var adminToken = await GetToken(admin);

            var          deletePath = $"{Routes.UserRoute}/{user.Id}";
            const string createPath = Routes.TodoRoute;

            _endSystems.SetBearerToken(adminToken);
            var deleteResponse = await _endSystems.Delete(deletePath);

            Assert.Equal(HttpStatusCode.NoContent, deleteResponse.Code);

            _endSystems.RemoveBearerToken();
            _endSystems.SetBearerToken(userToken);

            var model = new CreateTodoViewModel
            {
                Description = "They paved paradise and put up a parking lot",
                Due         = new DateTime(2000, 1, 1)
            };
            var body    = JsonStringBuilder.CreateTodoJsonBody(model.Description, model.Due.ToString());
            var content = new StringContent(body);

            // Act
            var response = await _endSystems.Post(createPath, content);

            // Assert
            Assert.Equal(HttpStatusCode.Unauthorized, response.Code);

            // Tear down
            _endSystems.Dispose();
        }