Example #1
0
        public async Task PostTodoSuccess()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestColumns);
                var client = testScope.CreateClient();

                var response = await client.PostAsJsonAsync("/api/todos",
                                                            new BLL.Todo(
                                                                null,
                                                                "Todo3",
                                                                "salala",
                                                                "2021-04-30T10:54",
                                                                0,
                                                                1)
                                                            );

                var responseBody = await response.Content.ReadFromJsonAsync <BLL.Todo>();

                var insertedTodo = testScope.GetDbTableContent <DAL.Todo>().Single(t => t.Id == responseBody.Id);

                Assert.IsNotNull(response);
                Assert.AreEqual(System.Net.HttpStatusCode.Created, response.StatusCode);
                Assert.IsNotNull(responseBody);
                Assert.AreEqual(insertedTodo, MapDtoToEntity(responseBody));
            }
        }
Example #2
0
        public async Task PutTodoSuccess()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                var client = testScope.CreateClient();
                testScope.AddSeedEntities(TestColumns);
                testScope.AddSeedEntities(TestTodos);
                int    queryId     = 1;
                int    todoId      = queryId;
                string uniqueTitle = "UniqueTitle";

                var response = await client.PutAsJsonAsync($"/api/todos/{queryId}",
                                                           new BLL.Todo(
                                                               todoId,
                                                               uniqueTitle,
                                                               null,
                                                               "2021-04-30T10:54",
                                                               0,
                                                               1)
                                                           );

                var updatedTodo = testScope.GetDbTableContent <DAL.Todo>().Single(t => t.Id == todoId);

                Assert.IsNotNull(response);
                Assert.AreEqual(System.Net.HttpStatusCode.NoContent, response.StatusCode);
                Assert.AreEqual(updatedTodo.Title, uniqueTitle);
            }
        }
Example #3
0
        public async Task PostColumnWithId()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                var client = testScope.CreateClient();

                var response = await client.PostAsJsonAsync("/api/columns", new BLL.Column(4, "TestPost"));

                Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode);
            }
        }
Example #4
0
        public async Task PostColumnWithNotUniqueTitle()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestColumns);
                var client = testScope.CreateClient();

                var response = await client.PostAsJsonAsync("/api/columns", new BLL.Column(null, "Column1"));

                Assert.AreEqual(System.Net.HttpStatusCode.Conflict, response.StatusCode);
            }
        }
Example #5
0
        public async Task UpdateColumnWithNotExistingId()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestColumns);
                var client = testScope.CreateClient();

                var response = await client.PutAsJsonAsync("/api/columns/4", new BLL.Column(4, "Column4"));

                Assert.IsNotNull(response);
                Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode);
            }
        }
Example #6
0
        public async Task DeleteNotExistingColumn()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestColumns);
                var client = testScope.CreateClient();

                var response = await client.DeleteAsync("/api/columns/4");

                Assert.IsNotNull(response);
                Assert.AreEqual(System.Net.HttpStatusCode.NotFound, response.StatusCode);
            }
        }
Example #7
0
        public async Task GetSingleColumnWhenDoesNotExist()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestColumns);
                var client = testScope.CreateClient();

                int id       = 4;
                var response = await client.GetAsync($"/api/columns/{id}");

                Assert.AreEqual(System.Net.HttpStatusCode.NotFound, response.StatusCode);
            }
        }
Example #8
0
        public async Task GetColumnsWhenEmpty()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                var client   = testScope.CreateClient();
                var response = await client.GetAsync("/api/columns");

                response.EnsureSuccessStatusCode();
                var actual = await response.Content.ReadFromJsonAsync <BLL.Column[]>();

                Assert.IsNotNull(actual);
                Assert.AreEqual(0, actual.Length);
            }
        }
Example #9
0
        public async Task DeleteColumnSuccess()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestColumns);
                var client = testScope.CreateClient();

                int id       = 1;
                var response = await client.DeleteAsync($"/api/columns/{id}");

                var deletedColumn = testScope.GetDbTableContent <DAL.Column>().SingleOrDefault(c => c.Id == id);

                Assert.IsNotNull(response);
                Assert.AreEqual(System.Net.HttpStatusCode.NoContent, response.StatusCode);
                Assert.IsNull(deletedColumn);
            }
        }
Example #10
0
        public async Task GetSingleColumnWhenExists()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestColumns);
                int id       = 1;
                var client   = testScope.CreateClient();
                var response = await client.GetAsync($"/api/columns/{id}");

                response.EnsureSuccessStatusCode();
                var actual = await response.Content.ReadFromJsonAsync <BLL.Column>();

                var actualEntity = MapDtoToEntity(actual);

                Assert.IsNotNull(actual);
                Assert.AreEqual(TestColumns.Single(tc => tc.Id == id), actualEntity);
            }
        }
Example #11
0
        public async Task UpdateColumnSuccess()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestColumns);
                var client = testScope.CreateClient();

                int id       = 2;
                var update   = new BLL.Column(id, "Column22");
                var response = await client.PutAsJsonAsync($"/api/columns/{id}", update);

                var updatedColumn = testScope.GetDbTableContent <DAL.Column>().Single(c => c.Id == id);

                Assert.IsNotNull(response);
                Assert.AreEqual(System.Net.HttpStatusCode.NoContent, response.StatusCode);
                Assert.AreEqual(update, MapEntityToDto(updatedColumn));
            }
        }
Example #12
0
        public async Task PostColumnSuccess()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestColumns);
                var client = testScope.CreateClient();

                var response = await client.PostAsJsonAsync("/api/columns", new BLL.Column(null, "Column4"));

                var responseBody = await response.Content.ReadFromJsonAsync <BLL.Column>();

                var insertedColumn = testScope.GetDbTableContent <DAL.Column>().Single(c => c.Id == responseBody.Id);

                Assert.IsNotNull(response);
                Assert.AreEqual(System.Net.HttpStatusCode.Created, response.StatusCode);
                Assert.IsNotNull(responseBody);
                Assert.AreEqual(insertedColumn, MapDtoToEntity(responseBody));
            }
        }
Example #13
0
        public async Task PostTodoToNotExistingColumn()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                var client = testScope.CreateClient();

                var response = await client.PostAsJsonAsync("/api/todos",
                                                            new BLL.Todo(
                                                                null,
                                                                "TestPost",
                                                                "Desc",
                                                                "2021-04-30T10:54",
                                                                0,
                                                                3)
                                                            );

                Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode);
            }
        }
Example #14
0
        public async Task PutTodoWithoutId()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                var client  = testScope.CreateClient();
                int queryId = 1;

                var response = await client.PutAsJsonAsync($"/api/todos/{queryId}",
                                                           new BLL.Todo(
                                                               null,
                                                               "TestPost",
                                                               "Desc",
                                                               "2021-04-30T10:54",
                                                               0,
                                                               1)
                                                           );

                Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode);
            }
        }
Example #15
0
        public async Task PutTodoToNotExistingColumn()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                var client  = testScope.CreateClient();
                int queryId = 1;
                int todoId  = queryId;

                var response = await client.PutAsJsonAsync($"/api/todos/{queryId}",
                                                           new BLL.Todo(
                                                               todoId,
                                                               "UpdatedTodo1",
                                                               null,
                                                               "2021-04-30T10:54",
                                                               0,
                                                               3)
                                                           );

                Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode);
            }
        }
Example #16
0
        public async Task PostTodoWithNotUniqueTitle()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestColumns);
                testScope.AddSeedEntities(TestTodos);
                var client = testScope.CreateClient();

                var response = await client.PostAsJsonAsync("/api/todos",
                                                            new BLL.Todo(
                                                                null,
                                                                "Todo1",
                                                                "salala",
                                                                "2021-04-30T10:54",
                                                                0,
                                                                1)
                                                            );

                Assert.AreEqual(System.Net.HttpStatusCode.Conflict, response.StatusCode);
            }
        }
Example #17
0
        public async Task GetColumnsWithData()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                testScope.AddSeedEntities(TestColumns);

                var client   = testScope.CreateClient();
                var response = await client.GetAsync("/api/columns");

                response.EnsureSuccessStatusCode();
                var actual = await response.Content.ReadFromJsonAsync <BLL.Column[]>();

                DAL.Column[] actualEntities = new DAL.Column[TestColumns.Length];
                for (int i = 0; i < TestColumns.Length; i++)
                {
                    actualEntities[i] = MapDtoToEntity(actual[i]);
                }

                Assert.IsNotNull(actual);
                CollectionAssert.AreEquivalent(TestColumns, actualEntities);
            }
        }
Example #18
0
        public async Task PutTodoWithNotUniqueTitle()
        {
            using (var testScope = TestWebAppFactory.Create())
            {
                var client = testScope.CreateClient();
                testScope.AddSeedEntities(TestColumns);
                testScope.AddSeedEntities(TestTodos);
                int queryId = 1;
                int todoId  = queryId;

                var response = await client.PutAsJsonAsync($"/api/todos/{queryId}",
                                                           new BLL.Todo(
                                                               todoId,
                                                               "Todo2",
                                                               null,
                                                               "2021-04-30T10:54",
                                                               0,
                                                               1)
                                                           );

                Assert.AreEqual(System.Net.HttpStatusCode.Conflict, response.StatusCode);
            }
        }