public void Add_Valid_ShouldReturnStatusCode200AndNotNullContent() { var mockUnitOfWork = Mock.Create<IUnitOfWork>(); School school = new School() { Location = "Location", Name = "Name" }; Student studentEntity = new Student() { FirstName = "Pesho", LastName = "Peshov", Age = 16, Grade = 10, School = school, Marks = new List<Mark>() { new Mark() { Subject = "math", Value = 6 } } }; bool isItemAdded = false; Mock.Arrange(() => mockUnitOfWork.SchoolsRepository.Get(Arg.IsAny<int>())) .Returns(school); Mock.Arrange(() => mockUnitOfWork.StudentsRepository.Add(Arg.IsAny<Student>())) .DoInstead(() => isItemAdded = true) .Returns(studentEntity); var server = new InMemoryHttpServer<Student>("http://localhost/", mockUnitOfWork); var response = server.CreatePostRequest("api/students", studentEntity); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsTrue(isItemAdded); Assert.IsNotNull(response.Content); }
public void PostNewBugWithoutLogDateAndEmptyDescriptionShouldReturn400() { var bugLoggerData = this.MockUnitOfWorkForActionAll(); var bug = new CreateBugModel(); var server = new InMemoryHttpServer <Bug>(InMemoryServerUrl, bugLoggerData); var response = server.CreatePostRequest("/api/Bugs/Create", bug); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public void PostNewBugWhenTextIsNullShouldReturn400() { var repo = Mock.Create<IBugTrackerData>(); var bug = new Bug { Text = null }; var server = new InMemoryHttpServer<Bug>(InMemoryServerUrl, repo); var response = server.CreatePostRequest("/api/Bugs/Log", bug); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public void AddThreeStudents_GetByMathResult_CheckIsCountCorrect() { var firstStudent = MakeSimpleStudent("Nikolay", "Kostov", 4.00); var secondStudent = MakeSimpleStudent("Svetlin", "Nakov", 5.00); var thirdStudent = MakeSimpleStudent("Doncho", "Minkov", 6.00); var repository = new FakeRepository<Student>(); var server = new InMemoryHttpServer<Student>("http://localhost/", repository); // Post student server.CreatePostRequest("api/students", firstStudent); server.CreatePostRequest("api/students", secondStudent); server.CreatePostRequest("api/students", thirdStudent); // Get all students that have a mark for MATH and it is above 5.00 var responseStudents = server .CreateGetRequest("api/students?subject=math&value=5.00") .Content.ReadAsAsync<List<Student>>().Result; Assert.AreEqual(2, responseStudents.Count); }
public void PostNewBugWhenDescriptionIsNullShouldReturn400() { var bugLoggerData = this.MockUnitOfWorkForActionAll(); var bug = new CreateBugModel() { Description = null, LogDate = DateTime.Now }; var server = new InMemoryHttpServer<Bug>(InMemoryServerUrl, bugLoggerData); var response = server.CreatePostRequest("/api/Bugs/Create", bug); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public void PostNewValidBugShouldReturn201() { var bugLoggerData = this.MockUnitOfWorkForActionAll(); var bug = new CreateBugModel() { Description = "bug-1", LogDate = DateTime.Now }; var server = new InMemoryHttpServer <Bug>(InMemoryServerUrl, bugLoggerData); var response = server.CreatePostRequest("/api/Bugs/Create", bug); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); }
public void PostNewBugWhenTextIsValidShouldReturn201AndLocationHeader() { var mockUnitOfWork = Mock.Create<IBugTrackerData>(); var bug = this.GetValidBug(); Mock.Arrange(() => mockUnitOfWork.Bugs.Add(Arg.IsAny<Bug>())).Returns(() => bug); var server = new InMemoryHttpServer<Bug>(InMemoryServerUrl, mockUnitOfWork); var response = server.CreatePostRequest("/api/Bugs/Log", bug); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); Assert.IsNotNull(response.Headers.Location); }
public void PostTeamWorkWhenNameIsNullShouldReturnStatusCode400() { var mockRepository = Mock.Create<ITwsData>(); Mock.Arrange(() => mockRepository.TeamWorks .Add(Arg.Matches<TeamWork>(cat => cat.Name == null))) .Throws<NullReferenceException>(); var server = new InMemoryHttpServer<TeamWork>("http://localhost/", mockRepository.TeamWorks); var response = server.CreatePostRequest("/teamwork/create", Entities.GetValidTeamWork()); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public void PostEmptyStudent() { //var school = new School().AddSchoolToDatabase( var mockRepository = Mock.Create<DbStudentRepository>(); var student = new Student(); Mock.Arrange(() => mockRepository.Add(Arg.IsAny<Student>())) .Throws(new DbEntityValidationException()); var server = new InMemoryHttpServer<Student>("http://localhost/", mockRepository); var responce = server.CreatePostRequest("api/students", JsonConvert.SerializeObject(student)); Assert.AreEqual((int)responce.StatusCode, 500); }
public void PostStudent_WhenNameIsNull_ShouldReturnStatusCode400() { var mockRepository = Mock.Create<IRepository<Student>>(); Mock.Arrange(() => mockRepository .Add(Arg.Matches<Student>(st => st.FirstName == null))) .Throws<NullReferenceException>(); var server = new InMemoryHttpServer<Student>("http://localhost/", mockRepository); var response = server.CreatePostRequest("api/Student", new Student() ); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public void PostCategory_WhenNameIsNull_ShouldReturnStatusCode400() { var mockRepository = Mock.Create<IRepository<Category>>(); Mock.Arrange(() => mockRepository .Add(Arg.Matches<Category>(cat => cat.Name == null))) .Throws<NullReferenceException>(); var server = new InMemoryHttpServer<Category>("http://localhost/", mockRepository); var response = server.CreatePostRequest("api/categories", new Category() { Name = null }); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public void Add_ValidStudent_CheckUserNamesAndCount() { var repository = new FakeRepository<Student>(); string firstName = "Nikolay"; string lastName = "Kostov"; double mathValue = 5.00; var student = MakeSimpleStudent(firstName, lastName, mathValue); var server = new InMemoryHttpServer<Student>("http://localhost/", repository); // Post student var request = server.CreatePostRequest("api/students", student); // Get posted student var responseStudent = server.CreateGetRequest("api/students").Content.ReadAsAsync<List<Student>>().Result; Assert.AreEqual(1, responseStudent.Count); Assert.AreEqual(firstName, responseStudent[0].FirstName); Assert.AreEqual(lastName, responseStudent[0].LastName); }
public void Add_StudentWithoutSchool_ShouldReturnStatusCode500() { var mockUnitOfWork = Mock.Create<IUnitOfWork>(); Student studentEntity = new Student() { FirstName = "Pesho", LastName = "Peshov", Age = 16, Grade = 10, Marks = new List<Mark>() { new Mark() { Subject = "math", Value = 6 } } }; Mock.Arrange(() => mockUnitOfWork.StudentsRepository .Add(Arg.Matches<Student>(st => st.School == null))) .Throws<ArgumentNullException>(); var server = new InMemoryHttpServer<Student>("http://localhost/", mockUnitOfWork); var response = server.CreatePostRequest("api/students", studentEntity); Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode); }
public void Post_WhenStudentLastNameIsNull_ShouldReturnStatusCode400() { var mockRepository = Mock.Create<IRepository<Student>>(); Mock.Arrange(() => mockRepository.Post(Arg.IsAny<Student>())) .Returns(() => new Student() { Id = 3 }); var server = new InMemoryHttpServer<Student>("http://localhost/", mockRepository); var response = server.CreatePostRequest("api/students/", new StudentModel() { Age = 14, FirstName = "Boiko", LastName = null, Grade = 8 }); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public void Post_WhenStudentIsCorrect_ShouldReturnStatusCode200AndSomeContent() { var mockRepository = Mock.Create<IRepository<Student>>(); Mock.Arrange(() => mockRepository.Post(Arg.IsAny<Student>())) .Returns(() => new Student() { Id = 3 } ); var server = new InMemoryHttpServer<Student>("http://localhost/", mockRepository); var response = server.CreatePostRequest("api/students/", new StudentModel() { Age = 11, FirstName = "Boiko", LastName = "Kanev", Grade = 4 }); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public void PostStudentWithoutSchool() { //var school = new School().AddSchoolToDatabase( var mockRepository = Mock.Create<DbStudentRepository>(); var student = new Student() .AddFirstName("ivan") .AddLastName("petkov") .AddAge(8) .AddGrade(2); Mock.Arrange(() => mockRepository.Add(Arg.IsAny<Student>())) .Throws(new DbEntityValidationException()); var server = new InMemoryHttpServer<Student>("http://localhost/", mockRepository); var responce = server.CreatePostRequest("api/students", JsonConvert.SerializeObject(student)); Assert.AreEqual(responce.StatusCode, HttpStatusCode.InternalServerError); }
public void PostStudent() { //var school = new School().AddSchoolToDatabase( var mockRepository = Mock.Create<DbStudentRepository>(); bool added = false; var student = new Student() .AddFirstName("ivan") .AddLastName("petkov") .AddAge(8) .AddGrade(2) .AddSchoolId(1); Mock.Arrange(() => mockRepository.Add(Arg.IsAny<Student>())) .DoInstead(() => added = true) .Returns(student); var server = new InMemoryHttpServer<Student>("http://localhost/", mockRepository); var responce = server.CreatePostRequest("api/students", JsonConvert.SerializeObject(student)); Assert.AreEqual(responce.StatusCode, HttpStatusCode.Created); Assert.IsTrue(added); }
public void Post_StudentWithouthName_ShouldReturnInternalErrorMsg() { var mockRepository = Mock.Create<DbStudentsRepository>(); var student = new Student() { Grade = 5, Age = 18 }; Mock.Arrange(() => mockRepository.Add(Arg.IsAny<Student>())) .Throws<ArgumentNullException>(); var server = new InMemoryHttpServer<Student>("http://localhost/", mockRepository); var responce = server.CreatePostRequest("api/students", JsonConvert.SerializeObject(student)); Assert.AreEqual(responce.StatusCode, HttpStatusCode.InternalServerError); }
public void Post_StudentWithValidContent_ShouldReturnStatusCode200AndStudentWithId() { var mockRepository = Mock.Create<DbStudentsRepository>(); bool added = false; var student = new Student() { FirstName = "Peter", LastName = "Petrov", Grade = 5, Age = 18, }; var studentEntity = new Student() { StudentId =1, FirstName = "Peter", LastName = "Petrov", Grade = 5, Age = 18, }; Mock.Arrange(() => mockRepository.Add(Arg.IsAny<Student>())) .DoInstead(() => added = true) .Returns(studentEntity); var server = new InMemoryHttpServer<Student>("http://localhost/", mockRepository); var response = server.CreatePostRequest("api/students", student); var content = JsonConvert.DeserializeObject<Student>((response.Content.ReadAsStringAsync().Result)); Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); Assert.IsTrue(added); Assert.IsTrue(content.StudentId == 1); }
public void PostStudent_WhenValid_ShouldReturnStatusCode201() { var mockRepository = Mock.Create<IRepository<Student>>(); Mock.Arrange(() => mockRepository .Add(Arg.Matches<Student>(st => st.FirstName == "Pesho" && st.LastName == "Peshev"))) .Returns( new Student() { FirstName = "Pesho", LastName = "Peshev" } ); var server = new InMemoryHttpServer<Student>("http://localhost/", mockRepository); var response = server.CreatePostRequest("api/students", new Student() { FirstName = "Pesho", LastName = "Peshev", }); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); }
public void PostStudentInvalidNameTest() { var repository = new FakeStudentRepository(); var school = new TownSchool { Name = "School", Location = "Town" }; var student = new Student { FirstName = null, LastName = "Ivanov", Age = 9, Grade = 4, TownSchool = school }; var server = new InMemoryHttpServer("http://localhost/"); var response = server.CreatePostRequest("api/students", student); Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode); }