public void Create_Creates_And_Saves_Car()
        {
            var company = new Company();

            underTest.Create(company);

            companyRepo.Received().Create(company);
        }
Beispiel #2
0
        public void Create_GoodWeather()
        {
            var companyToCreate = new CompanyRequest()
            {
                Name = "CrazyCells", Description = "The most crazy cells you can find out there"
            };
            var res = _controller.Create(companyToCreate) as OkNegotiatedContentResult <bool>;

            Assert.NotNull(res);
            Assert.IsTrue(res.Content);
            Assert.AreEqual(1, _context.Companies.ToList()[0].Id);
            Assert.AreEqual("CrazyCells", _context.Companies.ToList()[0].Name);
            Assert.AreEqual("The most crazy cells you can find out there", _context.Companies.ToList()[0].Description);
        }
        public void GetCompany_Create_StatusCode_201()
        {
            
            // Arrange
            var mockService = new Mock<ICompanyService>();
            long id = 12;

            var newCompanyDto = new CompanyDto()
            {
                Name = "test new",
                EstablishmentYear = 2018,
                Employees = new List<EmployeDto>() { new EmployeDto() { LastName = "Jan", FirstName = "Nowak", DateOfBirth = DateTime.Now, JobTitle = JobTitle.Developer.ToString() } }
            };
            mockService.Setup(s => s.Validate(newCompanyDto))
                .Returns(new ValidateDto());

            mockService.Setup(s => s.Create(newCompanyDto))
                .Returns(id);

            var controller = new CompanyController(mockService.Object);

            // Act
            var result = controller.Create(newCompanyDto);

            var okResult = Assert.IsType<ObjectResult>(result);            
            Assert.Equal(201, okResult.StatusCode);
            mockService.Verify();           
        }
Beispiel #4
0
        public async Task CreateEditDeleteAsync()
        {
            var userStoreMock = new Mock <IUserStore <ApplicationUser> >();

            // Arrange
            var companyController = new CompanyController(new UserManager <ApplicationUser>(userStoreMock.Object,
                                                                                            null, null, null, null, null, null, null, null));
            var carController = new CarController(new UserManager <ApplicationUser>(userStoreMock.Object,
                                                                                    null, null, null, null, null, null, null, null));

            var company = new Company {
                CompanyId = Guid.NewGuid()
            };
            var result = await companyController.Create(company);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);


            // Arrange
            var companyId = company.CompanyId;

            // Act
            var car = new Car {
                VIN = "YUTDGE98765432165", RegNr = "SOP963", CompanyId = company.CompanyId
            };

            result = await carController.Create(car);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);

            var carId = car.CarId;

            // Act
            result = await carController.Details(carId);

            // Assert
            Assert.IsType <ViewResult>(result);

            // Act

            result = await carController.Edit(carId);

            // Assert
            Assert.IsType <ViewResult>(result);

            // Act
            result = await carController.Edit(carId, car);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);

            // Act
            result = await companyController.DeleteConfirmed(companyId);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);
        }
Beispiel #5
0
        public async Task <CompanyViewModel> Create(CreateCompanyCommand command)
        {
            var response = await controller.Create(command) as CreatedResult;

            var viewmodel = response.Value as CompanyViewModel;

            return(viewmodel);
        }
Beispiel #6
0
        public void ReturnCreateView_WhenInvokedWithoutParams()
        {
            var companyServiceMock = new Mock <ICompanyService>();

            var controller = new CompanyController(companyServiceMock.Object);
            var result     = controller.Create() as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
        }
Beispiel #7
0
        public void ReturnCreateView_WhenInvokedAddReturnsFalse()
        {
            var companyServiceMock = new Mock <ICompanyService>();
            var companyModelMock   = new Mock <CompanyModel>();

            companyServiceMock.Setup(x => x.Add(companyModelMock.Object)).Returns(false);

            var controller = new CompanyController(companyServiceMock.Object);
            var result     = controller.Create(companyModelMock.Object) as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
        }
Beispiel #8
0
        public async Task ShouldCreateCompany()
        {
            var companyRequest = new CompanyRequestModel()
            {
                Name = "SERASA"
            };
            var companyResponse = new CompanyResponseModel(0, "SERASA", 50);

            _companyService.Create(companyRequest).Returns(companyResponse);

            var responseController = await _controller.Create(companyRequest) as ObjectResult;

            var response = responseController.Value as CompanyResponseModel;

            await _companyService.Received(1)
            .Create(Arg.Is <CompanyRequestModel>
                        (x => x.Name == "SERASA"));

            Assert.AreEqual((int)HttpStatusCode.Created, responseController.StatusCode);
            companyResponse.Should().BeEquivalentTo(response);
        }
Beispiel #9
0
        public void RedirectToIndexView_WhenCompanyIsCreated()
        {
            var companyServiceMock = new Mock <ICompanyService>();
            var companyModelMock   = new Mock <CompanyModel>();

            companyServiceMock.Setup(x => x.Add(companyModelMock.Object)).Returns(true);


            var controller = new CompanyController(companyServiceMock.Object);
            var result     = controller.Create(companyModelMock.Object) as RedirectToRouteResult;

            Assert.AreEqual(result.RouteValues["Action"], "Index");
        }
        public void CreateTest()
        {
            PartialViewResult rv = (PartialViewResult)_controller.Create();

            Assert.IsInstanceOfType(rv.Model, typeof(CompanyVM));

            CompanyVM vm = rv.Model as CompanyVM;
            Company   v  = new Company();

            v.ID      = 29;
            vm.Entity = v;
            _controller.Create(vm);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <Company>().FirstOrDefault();

                Assert.AreEqual(data.ID, 29);
                Assert.AreEqual(data.CreateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10);
            }
        }
Beispiel #11
0
        public void CreateCompany()
        {
            var userStoreMock = new Mock <IUserStore <ApplicationUser> >();

            // Arrange
            var companyController = new CompanyController(new UserManager <ApplicationUser>(userStoreMock.Object,
                                                                                            null, null, null, null, null, null, null, null));

            // Act
            var result = companyController.Create() as ViewResult;

            // Assert
            Assert.IsType <ViewResult>(result);
        }
        public void Insert()
        {
            //arrange
            var       dataSource = new Mock <ICompanyDM>();
            CompanyVM company    = new CompanyVM()
            {
                ID = 1, Name = "Anish", CompanyABN_CAN = "2134123", Description = "", URL = "abc.com"
            };

            dataSource.Setup(s => s.Insert(It.IsAny <CompanyVM>())).Returns(1).Verifiable();
            CompanyController controller = new CompanyController(dataSource.Object);
            ActionResult      result     = controller.Create(company) as ActionResult;

            //assert
            dataSource.Verify();
            Assert.NotNull(result);
        }
Beispiel #13
0
        public async Task CreateEditDeleteAsync()
        {
            var userStoreMock = new Mock <IUserStore <ApplicationUser> >();

            // Arrange
            var companyController = new CompanyController(new UserManager <ApplicationUser>(userStoreMock.Object,
                                                                                            null, null, null, null, null, null, null, null));
            var company = new Company();
            var result  = await companyController.Create(company);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);


            // Arrange
            var companyId = company.CompanyId;

            // Act
            result = await companyController.Details(companyId);

            // Assert
            Assert.IsType <ViewResult>(result);

            // Act
            result = await companyController.Edit(companyId);

            // Assert
            Assert.IsType <ViewResult>(result);

            // Act
            company = new Company();

            result = await companyController.Edit(companyId, company);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);

            // Act
            result = await companyController.DeleteConfirmed(companyId);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);
        }
Beispiel #14
0
        public void Create()
        {
            var     memoryStore = new List <Company>();
            Company companyStub = new Company {
                CompanyName = "Lviv"
            };
            var mock = new Mock <IRepository <Company> >();

            mock.Setup(repo => repo.GetAll()).Returns(memoryStore.AsQueryable());
            mock.Setup(repo => repo.Create(It.IsAny <Company>())).Returns((Company company) => {
                company.Id = 1;
                memoryStore.Add(company);
                return(company);
            });
            var factoryMock = new Mock <IRepositoryFactory>();

            factoryMock.Setup(f => f.GetRepository <Company>()).Returns(mock.Object);
            _companyController = new CompanyController(factoryMock.Object);
            var emptyJson = _companyController.GetAll();

            Assert.IsNotNull(emptyJson);
            var emptyStore = emptyJson.Value as List <Company>;

            Assert.IsNotNull(emptyStore);
            Assert.AreEqual(emptyStore.Count, 0);
            var json = _companyController.Create(companyStub);

            Assert.IsNotNull(json);
            var result = json.Value as Company;

            Assert.NotNull(result);
            Assert.AreEqual(result.Id, 1);
            Assert.AreEqual(result.CompanyName, companyStub.CompanyName);
            var notEmptyJson = _companyController.GetAll();

            Assert.IsNotNull(notEmptyJson);
            var notEmptyStore = notEmptyJson.Value as List <Company>;

            Assert.IsNotNull(notEmptyStore);
            Assert.AreEqual(notEmptyStore.Count, 1);
        }
        static void CreateCompany(CompanyController companyController)
        {
            Console.WriteLine("--------------------------------------");
            Console.WriteLine("Name of the company?");
            Console.WriteLine("--------------------------------------");
            string nameOfCompany = Console.ReadLine();

            Console.WriteLine("--------------------------------------");

            Console.WriteLine("FoundedDate of the company?");
            Console.WriteLine("--------------------------------------");
            DateTime foundedDateOfCompany = Convert.ToDateTime(Console.ReadLine());

            Console.WriteLine("--------------------------------------");

            var company = new Model.Company
            {
                Name        = nameOfCompany,
                FoundedDate = foundedDateOfCompany
            };

            companyController.Create(company);
        }
        public void GetCompany_Create_BadRequest()
        {
            // Arrange
            var mockService = new Mock<ICompanyService>();

            var newCompanyDto = new CompanyDto()
            {
                Name = "test",
                EstablishmentYear = 2018,
                Employees = new List<EmployeDto>() { new EmployeDto() { LastName = "Jan", FirstName = "Nowak", DateOfBirth = DateTime.Now, JobTitle = JobTitle.Developer.ToString() } }
            };

            var controller = new CompanyController(mockService.Object);
          
            // Assert
            controller.ModelState.AddModelError("Name", "Required");

            // Act
            var result = controller.Create(newCompanyDto);

            // Assert
            Assert.IsType<BadRequestObjectResult>(result);
        }
        public void GetCompany_Create_CompanyWithNameExist()
        {

            // Arrange
            var mockService = new Mock<ICompanyService>();
            var newCompanyDto = new CompanyDto()
            {
                Name = "test",
                EstablishmentYear = 2018,
                Employees = new List<EmployeDto>() { new EmployeDto() { LastName = "Jan", FirstName = "Nowak", DateOfBirth = DateTime.Now, JobTitle = JobTitle.Developer.ToString() } }
            };

            mockService.Setup(s => s.Validate(newCompanyDto))
                .Returns(new ValidateDto() { IsValid = false, Msg= $"Company: '{newCompanyDto.Name}' already exists in the database" });

            var controller = new CompanyController(mockService.Object);

            // Act
            var result = controller.Create(newCompanyDto);

            var badRequest = Assert.IsType<BadRequestObjectResult>(result);
            Assert.Equal($"Company: '{newCompanyDto.Name}' already exists in the database" , badRequest.Value);
            mockService.Verify();
        }