public void GetEmployeeShouldGetOneEntity()
 {
     var emploeeController = new EmployeeWCFController(new MemeoryEmployeeBoService());
     var item = emploeeController.GetEmployee(1);
     Assert.NotNull(item);
     Assert.IsType<Employee>(item);
 }
        public void GetEmployeeReturnsCorrectItemFromRepository()
        {
            // Arrange
            var product = new Employee { EmployeeID = 1, Title = "SD" };
            var controller = new EmployeeWCFController(new MemeoryEmployeeBoService());

            // Act
            var result = controller.GetEmployee(1);

            // Assert
            Assert.Equal(product.EmployeeID, result.EmployeeID);
        }
        public void GetAllProductsReturnsEverythingInRepository()
        {
            // Arrange
            var allItems = new List<Employee>
            {
                new Employee{EmployeeID=1,Title="SD"}
            };
            var controller = new EmployeeWCFController(new MemeoryEmployeeBoService());

            // Act
            var result = controller.GetAllEmployee();

            // Assert
            Assert.NotNull(result);
        }
        /// <summary>
        /// Posts the employee returns created status code.
        /// </summary>
        public void PostEmployeeReturnsCreatedStatusCode()
        {
            var controller = new EmployeeWCFController(new MemeoryEmployeeBoService());
            SetupControllerForTests(controller);

            var result = controller.PostEmployee(new Employee { EmployeeID = 1 });
            Assert.Equal(HttpStatusCode.Created, result.StatusCode);
        }
 public void GetProductThrowsWhenRepositoryReturnsNull()
 {
     var controller = new EmployeeWCFController(new MemeoryEmployeeBoService());
     Assert.Throws<HttpResponseException>(() => controller.GetEmployee(222));
 }
        public void PutEmployeeThrowsWhenRepositoryUpdateReturnsFalse()
        {
            //Arrange
            var controller = new EmployeeWCFController(new MemeoryEmployeeBoService());

            Assert.Throws<HttpResponseException>(() => controller.PutEmployee(new Employee() { EmployeeID=123}));
        }
        public void PutEmployeeUpdatesRepository()
        {
            //Arrange
            var controller = new EmployeeWCFController(new MemeoryEmployeeBoService());
            var item=new Employee { EmployeeID=1,Title="PM"};
         
            // Act
            controller.PutEmployee(item);
            var existEmployee = controller.GetEmployee(1);

            // Assert
            Assert.NotNull(existEmployee);
            Assert.Same(item, existEmployee);
        }
        public void DeleteEmployeeReturnsResponseMessageWithNoContentStatusCode()
        {
            var controller = new EmployeeWCFController(new MemeoryEmployeeBoService());

            var employee = new Employee { EmployeeID = 111 };
            var result = controller.DeleteEmployee(employee);

            Assert.IsType<HttpResponseMessage>(result);
            Assert.Equal(HttpStatusCode.NoContent, result.StatusCode);
        }
        public void DeleteEmployeeCallsRepositoryRemove()
        {
            int removedId = 123;
            var mockobject= new Mock<IEmployeeBoService>();
            mockobject.Setup(e => e.DelEmployee(It.Is<Employee>(i => i.EmployeeID == removedId))).Returns(true);
            var serviceclient =mockobject.Object;
            var controller = new EmployeeWCFController(serviceclient);
            var employee = new Employee { EmployeeID = removedId };
            controller.DeleteEmployee(employee);

            Assert.Equal(123, removedId);
        }
Esempio n. 10
0
        /// <summary>
        /// Posts the employee returns the correct location in response message.
        /// </summary>
        public void PostEmployeeReturnsTheCorrectLocationInResponseMessage()
        {
            var controller = new EmployeeWCFController(new MemeoryEmployeeBoService());
            SetupControllerForTests(controller);

            var result = controller.PostEmployee(new Employee { EmployeeID = 111 });
            Assert.Equal("http://localhost/api/employee/111", result.Headers.Location.ToString());
            Assert.Equal(HttpStatusCode.Created, result.StatusCode);

        }