Beispiel #1
0
        public void PostStudent_WhenValidStudent_ShouldReturnStatusCode201()
        {
            var fakeRepo = new FakeStudentRepository();

            var server =
                new InMemoryHttpServer <Student>("http://localhost/", fakeRepo);

            var response = server.CreatePostRequest("api/students",
                                                    new Student()
            {
                FirstName = "Minko",
                LastName  = "Markov",
                School    = new School(),
                Grade     = 5
            });

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
        }
        public void PostStudent_WhenNameIsNull_ShouldReturnStatusCode400()
        {
            var repository = Mock.Create<IRepository>();

            Mock.Arrange(() => repository
                .Create(Arg.Matches<Student>(s => s.FirstName == null)))
                .Throws<Exception>();


            var server = new InMemoryHttpServer("http://localhost/", repository);

            var response = server.CreatePostRequest("api/students",
                new Student()
                {
                    FirstName = null
                });

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Beispiel #3
0
        public void PostStudent_WhenNameIsNull_ShouldReturnStatusCode400()
        {
            var repository = Mock.Create <IRepository>();

            Mock.Arrange(() => repository
                         .Create(Arg.Matches <Student>(s => s.FirstName == null)))
            .Throws <Exception>();


            var server = new InMemoryHttpServer("http://localhost/", repository);

            var response = server.CreatePostRequest("api/students",
                                                    new Student()
            {
                FirstName = null
            });

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }