Esempio n. 1
0
        public async Task Can_404_When_Getting_A_Missing_Todo()
        {
            var fixture = new TodoDataFixture();
            var subject = new TodoController(fixture.Repository);
            var result  = (await subject.Get("BADID")).Result as NotFoundObjectResult;

            Assert.NotNull(result);
            Assert.Equal(404, result.StatusCode);
            Assert.IsAssignableFrom <ApiErrorModel>(result.Value);
            Assert.Equal(
                "not_found",
                ((ApiErrorModel)result.Value).Code
                );
        }
Esempio n. 2
0
        public async Task Can_Get_A_Todo()
        {
            var fixture = new TodoDataFixture();
            var subject = new TodoController(fixture.Repository);
            var result  = (await subject.Get("test-id")).Result as OkObjectResult;

            Assert.NotNull(result);
            Assert.Equal(200, result.StatusCode);
            Assert.Equal(
                TodoDataFixture.TodoApiModel,
                (TodoApiModel)result.Value,
                new TodoApiModelComparer()
                );
        }
Esempio n. 3
0
        public async Task Can_Get_All_Todos()
        {
            var fixture = new TodoDataFixture();
            var subject = new TodoController(fixture.Repository);
            var result  = (await subject.Get()).Result as OkObjectResult;

            Assert.NotNull(result);
            Assert.Equal(200, result.StatusCode);
            Assert.Equal(
                new[] { TodoDataFixture.TodoApiModel },
                ((IEnumerable <TodoApiModel>)result.Value).ToArray(),
                new TodoApiModelComparer()
                );
        }
Esempio n. 4
0
        public async Task Can_400_When_Posting_An_Invalid_Todo(string task)
        {
            var fixture = new TodoDataFixture();
            var subject = new TodoController(fixture.Repository);
            var request = new TodoRequestApiModel {
                Task = task
            };
            var result = (await subject.Post(request)).Result as BadRequestObjectResult;

            Assert.NotNull(result);
            Assert.Equal(400, result.StatusCode);
            Assert.Equal(
                "failed_validation",
                ((ApiErrorModel)result.Value).Code
                );
            Assert.Equal(
                new[] { "Test Value" },
                fixture.Repository.Values.Values.Select(x => x.Task).ToArray()
                );
        }
Esempio n. 5
0
        public async Task Can_Post_A_Todo()
        {
            var fixture = new TodoDataFixture();
            var subject = new TodoController(fixture.Repository);
            var request = new TodoRequestApiModel {
                Task = "Created Value"
            };
            var result = (await subject.Post(request)).Result as OkObjectResult;

            Assert.NotNull(result);
            Assert.Equal(200, result.StatusCode);
            Assert.False(String.IsNullOrWhiteSpace(((TodoApiModel)result.Value).Id));
            Assert.Equal(
                request.Task,
                ((TodoApiModel)result.Value).Task
                );
            Assert.Equal(
                new[] { "Created Value", "Test Value" },
                fixture.Repository.Values.Values.Select(x => x.Task).OrderBy(x => x).ToArray()
                );
        }
Esempio n. 6
0
        public async Task Can_404_When_Putting_A_Missing_Todo()
        {
            var fixture = new TodoDataFixture();
            var subject = new TodoController(fixture.Repository);
            var request = new TodoRequestApiModel {
                Task = "Updated value"
            };
            var result = (await subject.Put("BADID", request)).Result as NotFoundObjectResult;

            Assert.NotNull(result);
            Assert.Equal(404, result.StatusCode);
            Assert.IsAssignableFrom <ApiErrorModel>(result.Value);
            Assert.Equal(
                "not_found",
                ((ApiErrorModel)result.Value).Code
                );
            Assert.Equal(
                new[] { "Test Value" },
                fixture.Repository.Values.Values.Select(x => x.Task).ToArray()
                );
        }
Esempio n. 7
0
        public async Task Can_Put_A_Todo()
        {
            var fixture = new TodoDataFixture();
            var subject = new TodoController(fixture.Repository);
            var request = new TodoRequestApiModel {
                Task = "Updated Value"
            };
            var result = (await subject.Put("test-id", request)).Result as OkObjectResult;

            Assert.NotNull(result);
            Assert.Equal(200, result.StatusCode);
            Assert.Equal(
                TodoDataFixture.UpdatedTodoApiModel,
                (TodoApiModel)result.Value,
                new TodoApiModelComparer()
                );
            Assert.Equal(
                new[] { "Updated Value" },
                fixture.Repository.Values.Values.Select(x => x.Task).ToArray()
                );
        }