예제 #1
0
        public void UpdateShouldReturnCorrectValueWhenUpdateDuplicateValueButSameId()
        {
            var service = new ApoClassService(_apoClassRepository, _apoDepartmentRepository);

            var resource = new ApoClassForCreateOrEdit()
            {
                Name            = "Miscellaneous",
                ApoDepartmentId = 1
            };

            var compareObj = new ApoClassDto()
            {
                Name           = resource.Name,
                DepartmentId   = resource.ApoDepartmentId,
                Id             = 91,
                IsActive       = 1,
                Code           = _apoClass.Single(x => x.Id == 91).Code,
                DepartmentName = _apoDepartment.Single(x => x.Id == resource.ApoDepartmentId).Name
            };


            var sut = service.Edit(91, resource);

            Assert.IsType <ApoClassDto>(sut);
            AssertObjects.PropertyValuesAreEquals(sut, compareObj);
        }
        public void CreateProductTest()
        {
            var productController = new ProductController(_productService)
            {
                Request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Post,
                    RequestUri = new Uri(ServiceBaseURL + "/api/product")
                }
            };

            productController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            var newProduct = new ProductEntity()
            {
                ProductName = "Android Phone"
            };

            var maxProductIDBeforeAdd = _products.Max(a => a.ProductId);

            newProduct.ProductId = maxProductIDBeforeAdd + 1;
            productController.Post(newProduct);
            var addedProduct = new Product()
            {
                ProductName = newProduct.ProductName, ProductId = newProduct.ProductId
            };

            AssertObjects.PropertyValuesAreEquals(addedProduct, _products.Last());
        }
        public void ParseResponses_Escape()
        {
            //escaped
            var actual   = CommandBuilder.ParseResponses("-1 \"bad command.\"\n");
            var expected = new Response[] { new ErrorResponse()
                                            {
                                                Message = "bad command."
                                            } };

            AssertObjects.HaveEqualProperties(expected, actual, true);

            //not escaped
            actual   = CommandBuilder.ParseResponses("-1 bad_command.\n");
            expected = new Response[] { new ErrorResponse()
                                        {
                                            Message = "bad_command."
                                        } };
            AssertObjects.HaveEqualProperties(expected, actual, true);

            //not escaped
            actual   = CommandBuilder.ParseResponses("-1 bad command.\n");
            expected = new Response[] { new ErrorResponse()
                                        {
                                            Message = "bad"
                                        } };
            AssertObjects.HaveEqualProperties(expected, actual, true);
        }
예제 #4
0
        public void CreateProductTest()
        {
            var contactController = new ContactController(_contactService)
            {
                Request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Post,
                    RequestUri = new Uri(ServiceBaseURL + "v1/Contacts/Contact/Create")
                }
            };

            contactController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            var newContact = new ContactEntity()
            {
                FirstName = "Rackson"
            };

            var maxProductIDBeforeAdd = _contacts.Max(a => a.ID);

            newContact.ID = maxProductIDBeforeAdd + 1;
            contactController.Post(newContact);
            var addedcontact = new Contact()
            {
                FirstName = newContact.FirstName, ID = newContact.ID
            };

            AssertObjects.PropertyValuesAreEquals(addedcontact, _contacts.Last());
            Assert.That(maxProductIDBeforeAdd + 1, Is.EqualTo(_contacts.Last().ID));
        }
예제 #5
0
        public void UpdateShouldReturnCorrectValueWhenUpdateDuplicateValueButSameId()
        {
            var service = new ApoSubClassService(_apoClassRepository, _apoSubClassRepository);

            var resource = new ApoSubClassForCreateOrEdit()
            {
                Name       = "Import Frozen Appetizer",
                ApoClassId = 106
            };

            var compareObj = new ApoSubClassDto()
            {
                Name         = resource.Name,
                ApoClassId   = resource.ApoClassId,
                Id           = 105,
                IsActive     = 1,
                Code         = _apoSubClass.Single(x => x.Id == 105).Code,
                ApoClassName = _apoClass.Single(x => x.Id == resource.ApoClassId).Name
            };


            var sut = service.Edit(105, resource);

            Assert.IsType <ApoSubClassDto>(sut);
            AssertObjects.PropertyValuesAreEquals(sut, compareObj);
        }
        public void AddNewUserTest()
        {
            var newUser = new UserEntity()
            {
                User_ID     = 9,
                First_Name  = "Sunil",
                Last_Name   = "G",
                Employee_ID = 42343,
                Project_ID  = null,
                Task_ID     = null
            };

            var maxUserIDBeforeAdd = _user.Max(a => a.User_ID);

            newUser.User_ID = maxUserIDBeforeAdd + 1;

            _userService.CreateUsers(newUser);
            var addedUser = new User()
            {
                User_ID     = newUser.User_ID,
                First_Name  = newUser.First_Name,
                Last_Name   = newUser.Last_Name,
                Employee_ID = newUser.Employee_ID,
                Project_ID  = newUser.Project_ID,
                Task_ID     = newUser.Task_ID
            };

            AssertObjects.PropertyValuesAreEquals(addedUser, _user.Last());
            Assert.That(maxUserIDBeforeAdd + 1, Is.EqualTo(newUser.User_ID));
        }
        public void AddNewTaskTest()
        {
            var newTask = new TaskEntity()
            {
                Task_ID    = 2,
                Parent_ID  = 2,
                Project_ID = 2,
                Task1      = "DAL Layer -2",
                Start_Date = Convert.ToDateTime("2018-12-28"),
                End_Date   = Convert.ToDateTime("2018-12-31"),
                Priority   = "20",
                Status     = null
            };

            var maxTaskIDBeforeAdd = _task.Max(a => a.Task_ID);

            newTask.Task_ID = maxTaskIDBeforeAdd + 1;

            _taskService.CreateTask(newTask);
            var addedTask = new Task()
            {
                Task_ID    = newTask.Task_ID,
                Parent_ID  = newTask.Parent_ID,
                Project_ID = newTask.Project_ID,
                Task1      = newTask.Task1,
                Start_Date = newTask.Start_Date,
                End_Date   = newTask.End_Date,
                Priority   = newTask.Priority,
                Status     = newTask.Status
            };

            AssertObjects.PropertyValuesAreEquals(addedTask, _task.Last());
            Assert.That(maxTaskIDBeforeAdd + 1, Is.EqualTo(newTask.Task_ID));
        }
예제 #8
0
        public void ShouldReturnNoContentWhenSuccess()
        {
            var controller = new StudentsController(_unitOfWork, _urlHelper);
            var patch      = new JsonPatchDocument <StudentDTO>();

            patch.Operations.Add(new Operation <StudentDTO>("replace", "/Name", null, "PartialUpdate"));


            var studentInDb = _randomStudent.Single(x => x.Id == "2");
            var student     = new Student();

            student.Name         = "PartialUpdate";
            student.Id           = studentInDb.Id;
            student.BirthDate    = studentInDb.BirthDate;
            student.IsActived    = studentInDb.IsActived;
            student.DairyReports = studentInDb.DairyReports;



            var sut = controller.PartialUpdateStudent("2", patch);


            Assert.IsType <NoContentResult>(sut);
            AssertObjects.PropertyValuesAreEquals(student, studentInDb);
        }
예제 #9
0
        public void CreateTaskTest()
        {
            var taskController = new TaskController()
            {
                Request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Post,
                    RequestUri = new Uri(ServiceBaseURL + "Create")
                }
            };

            taskController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            var newTask = new TaskEntity()
            {
                Task_ID    = 2,
                Parent_ID  = 2,
                Project_ID = 2,
                Task1      = "DAL Layer -3",
                Start_Date = Convert.ToDateTime("2018-12-28"),
                End_Date   = Convert.ToDateTime("2018-12-31"),
                Priority   = "20",
                Status     = null
            };

            taskController.Post(newTask);

            _response = taskController.Get();
            var responseResultSearch = JsonConvert.DeserializeObject <List <vw_TaskSearch> >(_response.Content.ReadAsStringAsync().Result);
            var taskList             =
                responseResultSearch.Select(
                    taskEntity =>
                    new Task
            {
                Task_ID    = taskEntity.Task_ID,
                Parent_ID  = taskEntity.TaskParentID,
                Project_ID = taskEntity.TaskProjectID,
                Task1      = taskEntity.TaskName,
                Start_Date = taskEntity.Start_Date,
                End_Date   = taskEntity.End_Date,
                Priority   = taskEntity.TaskPriority,
                Status     = taskEntity.TaskStatus
            }).ToList();
            var addedtask = new Task()
            {
                Task_ID    = newTask.Task_ID,
                Parent_ID  = newTask.Parent_ID,
                Project_ID = newTask.Project_ID,
                Task1      = newTask.Task1,
                Start_Date = newTask.Start_Date,
                End_Date   = newTask.End_Date,
                Priority   = newTask.Priority,
                Status     = newTask.Status
            };

            AssertObjects.PropertyValuesAreEquals(addedtask, taskList.Last());
        }
        public void GetEpisodeInfoByRightIdTest()
        {
            var patientEpisodeInfo = _patientService.GetEpisodeInfoByPatientId(2);

            if (patientEpisodeInfo != null)
            {
                AssertObjects.PropertyValuesAreEquals(patientEpisodeInfo, _patients.Find(a => a.FirstName.Contains("Millicent")));
            }
        }
예제 #11
0
        public async Task GetByIdReturnCorrect()
        {
            var response = await _client.GetAsync("/api/students/1");

            response.EnsureSuccessStatusCode();
            var returnSession = await response.Content.ReadAsJsonAsync <StudentDTO>();

            AssertObjects.PropertyValuesAreEquals
                (returnSession, AutoMapper.Mapper.Map <StudentDTO>(_randomStudent.Single(x => x.Id == "1")));
        }
예제 #12
0
        public void GetProductByRightIdTest()
        {
            var mobileProduct = _productService.GetProductById(2);

            if (mobileProduct != null)
            {
                var product = _productService.MapProductEntityToProduct(mobileProduct);
                AssertObjects.PropertyValuesAreEquals(product, _products.Find(z => z.ProductName.Contains("Mobile")));
            }
        }
예제 #13
0
        public void ApoDivisionServiceShouldReturnCorrectIdWhenExist()
        {
            var service = new ApoDivisionService(_apoDivisionRepository, _apoGroupService);

            var sut = service.GetById(1);


            Assert.IsType <ApoDivisionDto>(sut);
            Assert.True(sut.IsActive == 1);
            AssertObjects.PropertyValuesAreEquals(sut, Mapper.Map <ApoDivisionDto>(_apoDivision.Single(x => x.Id == 1)));
        }
예제 #14
0
        public void GetProductByIdTest()
        {
            int id = 2;
            var productController = ControllerCreater("api/Products/" + id, HttpMethod.Get);

            response = productController.Get(id);
            var responseResult = JsonConvert.DeserializeObject <Product>(response.Content.ReadAsStringAsync().Result);

            Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
            AssertObjects.PropertyValuesAreEquals(responseResult, products.Find(a => a.Id == id));
        }
        public void GetProductByRightIdTest()
        {
            var mobileProduct = _productServices.GetProductById(2);

            if (mobileProduct != null)
            {
                Mapper.CreateMap <ProductEntity, Product>();
                var productModel = Mapper.Map <ProductEntity, Product>(mobileProduct);
                AssertObjects.PropertyValuesAreEquals(productModel, _products.Find(a => a.ProductName.Contains("Mobile")));
            }
        }
예제 #16
0
        public void ApoClassServiceReturnCorrectId()
        {
            var service       = new ApoSubClassService(_apoClassRepository, _apoSubClassRepository);
            var selectedClass = Mapper.Map <ApoSubClassDto>(_apoSubClass.Single(x => x.Id == 2));

            selectedClass.ApoClassName = _apoClass.Single(x => x.Id == selectedClass.ApoClassId).Name;

            var sut = service.GetById(2);


            AssertObjects.PropertyValuesAreEquals(sut, selectedClass);
        }
예제 #17
0
        public void GetProductOptionIdByProductIdTest()
        {
            var mobileProduct = _productService.GetOptionIdByProductId(Guid.Empty);

            if (mobileProduct != null)
            {
                Mapper.CreateMap <ProductOptionEntity, ProductOptionEntity>();
                var productModel = Mapper.Map <ProductOptionEntity, ProductOptionEntity>(mobileProduct);
                AssertObjects.PropertyValuesAreEquals(productModel,
                                                      _products.Find(a => a.Name.Contains("Samsung")));
            }
        }
예제 #18
0
        public void ApoDepartmentServiceGetByIdReturnCorrectApo()
        {
            var service = new ApoDepartmentService(_apoDivisionRepository, _apoGroupRepository, _apoDepartmentRepository);

            var sut = service.GetById(10);

            var compareObj = Mapper.Map <ApoDepartmentDto>(_apoDepartment.Single(x => x.Id == 10));

            compareObj.DivisionName = _apoDivision.Single(x => x.Id == compareObj.DivisionId).Name;
            compareObj.GroupName    = _apoGroup.Single(x => x.Id == compareObj.GroupId).Name;

            AssertObjects.PropertyValuesAreEquals(sut, compareObj);
        }
        public void Given_a_matching_product_code_When_found_in_repository_Then_retrieve_product_from_repository()
        {
            var mobileProduct = _productService.GetProductByCode("A001");

            if (mobileProduct != null)
            {
                Mapper.CreateMap <ProductModel, Product>();

                var productModel = Mapper.Map <ProductModel, Product>(mobileProduct);
                AssertObjects.PropertyValuesAreEquals(productModel,
                                                      _products.Find(a => a.ProductCode.Contains("A001")));
            }
        }
예제 #20
0
        public void CreateUserTest()
        {
            var userController = new UserController()
            {
                Request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Post,
                    RequestUri = new Uri(ServiceBaseURL + "Create")
                }
            };

            userController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            var newUser = new UserEntity()
            {
                User_ID     = 11,
                First_Name  = "Test",
                Last_Name   = "User3",
                Employee_ID = 600,
                Project_ID  = null,
                Task_ID     = null
            };

            userController.PostUser(newUser);

            _response = userController.Get();
            var responseResultSearch = JsonConvert.DeserializeObject <List <User> >(_response.Content.ReadAsStringAsync().Result);
            var userList             =
                responseResultSearch.Select(
                    userEntity =>
                    new User
            {
                User_ID     = userEntity.User_ID,
                First_Name  = userEntity.First_Name,
                Last_Name   = userEntity.Last_Name,
                Employee_ID = userEntity.Employee_ID,
                Project_ID  = userEntity.Project_ID,
                Task_ID     = userEntity.Task_ID
            }).ToList();
            var addeduser = new User()
            {
                User_ID     = newUser.User_ID,
                First_Name  = newUser.First_Name,
                Last_Name   = newUser.Last_Name,
                Employee_ID = newUser.Employee_ID,
                Project_ID  = newUser.Project_ID,
                Task_ID     = newUser.Task_ID
            };

            AssertObjects.PropertyValuesAreEquals(addeduser, userList.Last());
        }
예제 #21
0
        public void ApoDivisionServiceShouldReturnCorrectValueWhenUpdateSameValueToSameId()
        {
            var service = new ApoDivisionService(_apoDivisionRepository, _apoGroupService);

            var editApo = new ApoDivisionForCreateOrEdit()
            {
                Name = "Food",
            };

            var sut = service.Edit(0, editApo);

            Assert.Equal(sut.Id, 0);
            AssertObjects.PropertyValuesAreEquals(sut, Mapper.Map <ApoDivisionDto>(_apoDivision.Single(x => x.Id == 0)));
        }
        public void GetProductByRightIdTest()
        {
            var mobileProduct = _productService.GetProductById(2);

            if (mobileProduct != null)
            {
                var config = new MapperConfiguration(cfg =>
                                                     cfg.CreateMap <ProductEntity, Product>());

                var mapper       = config.CreateMapper();
                var productModel = mapper.Map <ProductEntity, Product>(mobileProduct);
                AssertObjects.PropertyValuesAreEquals(productModel, _products.Find(a => a.ProductName.Contains("Mobile")));
            }
        }
예제 #23
0
        public void GetProductByRightIdTest()
        {
            var rigthId            = 2;
            var coreServiceProduct = productService.GetProductById(rigthId);

            if (coreServiceProduct != null)
            {
                var productModel = new Product
                {
                    Id = coreServiceProduct.Id, Name = coreServiceProduct.Name, CreateDate = coreServiceProduct.CreateDate, isActive = coreServiceProduct.isActive
                };
                AssertObjects.PropertyValuesAreEquals(productModel,
                                                      expectedProducts.Find(a => (a.Id == rigthId)));
            }
        }
        public void GetUserByRightIdTest()
        {
            var user = _userService.GetUserById(1);

            if (user != null)
            {
                var config = new MapperConfiguration(cfg => {
                    cfg.CreateMap <UserEntity, User>();
                });
                IMapper mapper    = config.CreateMapper();
                var     userModel = mapper.Map <UserEntity, User>(user);

                AssertObjects.PropertyValuesAreEquals(userModel,
                                                      _user.Find(a => a.First_Name.Contains("Rajj")));
            }
        }
예제 #25
0
        public void ApoDivisionShouldReturnCorrectvaluewhenSearchByName()
        {
            var service = new ApoDivisionService(_apoDivisionRepository, _apoGroupService);

            var searchObj = new ApoDivisionForCreateOrEdit()
            {
                Name = "Food"
            };

            var sut = service.GetByName(searchObj);

            var shouldEqual = _apoDivision.Single(x => x.Name.Equals(searchObj.Name));


            AssertObjects.PropertyValuesAreEquals(sut, Mapper.Map <ApoDivisionDto>(shouldEqual));
        }
        public void GetTaskByRightIdTest()
        {
            var task = _taskService.GetTaskById(1);

            if (task != null)
            {
                var config = new MapperConfiguration(cfg => {
                    cfg.CreateMap <TaskEntity, Task>();
                });
                IMapper mapper    = config.CreateMapper();
                var     taskmodel = mapper.Map <TaskEntity, Task>(task);

                AssertObjects.PropertyValuesAreEquals(taskmodel,
                                                      _task.Find(a => a.Task1.Contains("DAL Layer -1")));
            }
        }
        public void GenerateTokenByUserIdTest()
        {
            const int userId = 1;
            var       maxTokenIdBeforeAdd = _tokens.Max(a => a.TokenId);
            var       tokenEntity         = _tokenServices.GenerateToken(userId);
            var       newTokenDataModel   = new Token()
            {
                AuthToken = tokenEntity.AuthToken,
                TokenId   = maxTokenIdBeforeAdd + 1,
                ExpiresOn = tokenEntity.ExpiresOn,
                IssuedOn  = tokenEntity.IssuedOn,
                UserId    = tokenEntity.UserId
            };

            AssertObjects.PropertyValuesAreEquals(newTokenDataModel, _tokens.Last());
        }
예제 #28
0
        public void AddNewProductTest()
        {
            var newProduct = new ProductEntity();

            newProduct.ProductName = "Android Phone";

            var maxProductIdBeforeAdd = _products.Max(a => a.ProductId);

            newProduct.ProductId = maxProductIdBeforeAdd + 1;
            _productService.CreateProduct(newProduct);
            var addedProduct = new Product {
                ProductId = newProduct.ProductId, ProductName = newProduct.ProductName
            };

            AssertObjects.PropertyValuesAreEquals(addedProduct, _products.Last());
            Assert.That(maxProductIdBeforeAdd + 1, Is.EqualTo(_products.Last().ProductId));
        }
예제 #29
0
        public void ApoGroupShouldReturnCorrectvaluewhenSearchByName()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var searchObj = new ApoGroupForCreateOrUpdate()
            {
                Name = "Packaged"
            };

            var sut = service.GetByName(searchObj);

            var compareObj = Mapper.Map <ApoGroupDto>(_apoGroup.Single(x => x.Name.Equals(searchObj.Name)));

            compareObj.DivisionName = _apoDivision.Single(x => x.Id == compareObj.DivisionId).Name;

            AssertObjects.PropertyValuesAreEquals(sut, Mapper.Map <ApoGroupDto>(compareObj));
        }
예제 #30
0
        public void CreateProjectTest()
        {
            var projectController = new ProjectController()
            {
                Request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Post,
                    RequestUri = new Uri(ServiceBaseURL + "Create")
                }
            };

            projectController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            var newProject = new ProjectEntity()
            {
                Project_ID = 0,
                Project1   = "Project Created New ",
                Priority   = "3",
                Start_Date = Convert.ToDateTime("2018-01-17"),
                End_Date   = Convert.ToDateTime("2018-01-22")
            };

            projectController.Post(newProject);

            _response = projectController.Get();
            var responseResultSearch = JsonConvert.DeserializeObject <List <vw_ProjectSearch> >(_response.Content.ReadAsStringAsync().Result);
            var projectList          =
                responseResultSearch.Select(
                    projectEntity =>
                    new Project
            {
                Project_ID = projectEntity.Project_ID,
                Project1   = projectEntity.ProjectName,
                Priority   = projectEntity.Project_Priority,
                Start_Date = projectEntity.Start_Date,
                End_Date   = projectEntity.End_Date
            }).ToList();
            var addedproject = new Project()
            {
                Project1   = newProject.Project1,
                Project_ID = newProject.Project_ID
            };

            AssertObjects.PropertyValuesAreEquals(addedproject, projectList.Last());
        }