Exemple #1
0
        public void MakeControllerGetAllTest()
        {
            //Arange
            IncludeAllMappings.include();
            var context         = new VehicleContext();
            var repository      = new Repository.Repositorys.Repository(context, new UnitOfWorkFactory(new UnitOfWork(context)));
            var makeRepository  = new MakeRepository(repository);
            var modelRepository = new ModelRepository(repository);
            var makeService     = new MakeService(makeRepository, modelRepository);
            var testController  = new MakeController(makeService);

            testController.Request       = new HttpRequestMessage();
            testController.Configuration = new HttpConfiguration();

            //Add make
            var vMake = new VehicleMakeView()
            {
                Name = "MakeControllerGetAllTest", Abrv = "MakeControllerGetAllTest"
            };

            Task.Run(async() =>
            {
                var response = await testController.Add(vMake);
                Assert.IsNotNull(response);
            }).GetAwaiter().GetResult();

            Task.Run(async() =>
            {
                //Act
                var result = await testController.GetAll();
                //Assert
                Assert.IsNotNull(result);
            }).GetAwaiter().GetResult();
        }
Exemple #2
0
        public void MakeControllerUpdateTest()
        {
            //Arange
            IncludeAllMappings.include();
            var context         = new VehicleContext();
            var repository      = new Repository.Repositorys.Repository(context, new UnitOfWorkFactory(new UnitOfWork(context)));
            var makeRepository  = new MakeRepository(repository);
            var modelRepository = new ModelRepository(repository);
            var makeService     = new MakeService(makeRepository, modelRepository);
            var testController  = new MakeController(makeService);

            testController.Request       = new HttpRequestMessage();
            testController.Configuration = new HttpConfiguration();

            //Add make
            var vMake = new VehicleMakeView()
            {
                Name = "MakeControllerUpdateTest", Abrv = "MakeControllerUpdateTest"
            };

            Task.Run(async() =>
            {
                var response = await testController.Add(vMake);
                Assert.IsNotNull(response);
            }).GetAwaiter().GetResult();

            //Get make
            VehicleMakeView      targetItem = null;
            JavaScriptSerializer JSS        = new JavaScriptSerializer();

            Task.Run(async() =>
            {
                var response = await testController.GetAll();
                Assert.IsNotNull(response);

                IEnumerable <VehicleMakeView> obj = JSS.Deserialize <IEnumerable <VehicleMakeView> >(response.Content.ReadAsStringAsync().Result);
                targetItem = obj.LastOrDefault();
            }).GetAwaiter().GetResult();

            targetItem.Name = "MakeControllerUpdateTestTested";

            Task.Run(async() =>
            {
                //Act
                var response = await testController.Update(targetItem);
                //Assert
                int obj = JSS.Deserialize <int>(response.Content.ReadAsStringAsync().Result);
                Assert.AreEqual(1, obj);
            }).GetAwaiter().GetResult();
        }
 public MakeController_Test() : base()
 {
     _testTarget = new MakeController(_mockService.Object);
 }