Exemplo n.º 1
0
        public void TestGetRequestWhenThereIsDataInRepoShouldReturnThatData()
        {
            // arrange
            Bug[] bugs =
            {
                new Bug {
                    Content = "Bug1"
                },
                new Bug {
                    Content = "Bug2"
                },
                new Bug {
                    Content = "Bug3"
                }
            };

            var repoMock = new Mock <IRepository <Bug> >();

            repoMock.Setup(repo => repo.All()).Returns(bugs.AsQueryable());

            var server = new InMemoryHttpServer <Bug>(BugLoggerServicesUrl, repoMock.Object);

            // act
            var response = server.CreateGetRequest("/bugs");

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(response.Content);
        }
Exemplo n.º 2
0
        public void TestDeleteRequestWhenBugIdIsValidShouldDeleteBug()
        {
            // arrange
            List <Bug> bugs = new List <Bug>
            {
                new Bug {
                    BugId = 2014, Content = "Test bug"
                }
            };

            var repoMock = new Mock <IRepository <Bug> >();

            repoMock.Setup(repo => repo.All()).Returns(bugs.AsQueryable());
            repoMock.Setup(repo => repo.Delete(It.IsAny <Bug>()))
            .Callback((Bug toDelete) => bugs.Remove(toDelete));

            var server = new InMemoryHttpServer <Bug>(BugLoggerServicesUrl, repoMock.Object);

            // act
            var response = server.CreateDeleteRequest("/bugs/2014");

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(response.Content);
            Assert.IsTrue(bugs.Count == 0);
        }
Exemplo n.º 3
0
        public void TestPostRequestWhenBugIsInvalidShouldReturnBadRequest()
        {
            // arrange
            Bug bug = new Bug {
                BugId = 2014
            };

            var repoMock = new Mock <IRepository <Bug> >();

            var server = new InMemoryHttpServer <Bug>(BugLoggerServicesUrl, repoMock.Object);

            // act
            var response = server.CreatePostRequest("/bugs", bug);

            // assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Exemplo n.º 4
0
        public void TestPostRequestWhenBugIsValidShouldReturn201Created()
        {
            // arrange
            Bug bug = new Bug {
                BugId = 2014, Content = "Valid bug"
            };

            var repoMock = new Mock <IRepository <Bug> >();

            var server = new InMemoryHttpServer <Bug>(BugLoggerServicesUrl, repoMock.Object);

            // act
            var response = server.CreatePostRequest("/bugs", bug);

            // assert
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.AreEqual(response.Headers.Location, BugLoggerServicesUrl + "/bugs/" + bug.BugId);
        }
Exemplo n.º 5
0
        public void TestPutRequestWhenBugIsValidShouldUpdateBug()
        {
            // arrange
            Bug bug = new Bug {
                BugId = 2014, Content = "Test bug"
            };

            var repoMock = new Mock <IRepository <Bug> >();

            repoMock.Setup(repo => repo.All()).Returns((new Bug[] { bug }).AsQueryable());

            var server = new InMemoryHttpServer <Bug>(BugLoggerServicesUrl, repoMock.Object);

            // act
            var response = server.CreatePutRequest("/bugs/2014", bug);

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(response.Content);
        }