Exemplo n.º 1
0
        public void GetMany_with_existing_returns_records_in_data_prop()
        {
            // Act
            var result = _controller.Get().Result as ObjectResult;

            // Assert
            Assert.IsTrue(UnitTestExtensions.HasDataProperty(result));
        }
Exemplo n.º 2
0
        public void GetMany_with_existing_returns_all_records_of_type()
        {
            // Act
            var result        = _controller.Get().Result as ObjectResult;
            var viewModelList = UnitTestExtensions.ExtractFromDataObject <IEnumerable <LookupVM> >(result?.Value);

            // Assert
            Assert.IsTrue(viewModelList.Count() == _fakeLookups.Count);
            Assert.IsInstanceOfType(viewModelList, typeof(IEnumerable <LookupVM>));
        }
Exemplo n.º 3
0
        public void Get_by_existing_Id_returns_correct_item()
        {
            // Act
            var result = _controller.Get(1).Result as ObjectResult;
            var data   = UnitTestExtensions.ExtractFromDataObject <LookupVM>(result?.Value);

            // assert
            Assert.IsInstanceOfType(data, typeof(LookupVM));
            Assert.AreEqual(_fakeLookup.ID, data.id);
        }
Exemplo n.º 4
0
        public void Get_by_existing_Id_returns_correct_item_in_data_obj()
        {
            // Act
            var result = _controller.Get(1).Result as ObjectResult;
            var data   = UnitTestExtensions.ExtractFromDataObject <ScheduleRuleVM>(result?.Value);

            // assert
            Assert.IsInstanceOfType(data, typeof(ScheduleRuleVM));
            Assert.AreEqual(_fakeScheduleRule.ID, data.id);
            Assert.IsTrue(UnitTestExtensions.HasDataProperty(result));
        }
        public void GetMany_with_existing_returns_all_records_of_type_in_data_object()
        {
            // Act
            var result        = _controller.Get().Result as ObjectResult;
            var viewModelList = UnitTestExtensions.ExtractFromDataObject <IEnumerable <TransportProviderVM> >(result?.Value);

            // Assert
            Assert.IsTrue(viewModelList.Count() == _fakeTransportProviders.Count);
            Assert.IsInstanceOfType(viewModelList, typeof(IEnumerable <TransportProviderVM>));
            Assert.IsTrue(UnitTestExtensions.HasDataProperty(result));
        }
        public void GetMany_with_existing_configs_returns_all_records_of_type()
        {
            // Act
            var result       = _controller.Get();
            var typedResult  = (result.Result as ObjectResult).Value;
            var configVMList = UnitTestExtensions.ExtractFromDataObject <IEnumerable <ConfigVM> >(typedResult);

            // Assert
            Assert.IsTrue(configVMList.Count() == 5);
            Assert.IsInstanceOfType(configVMList, typeof(IEnumerable <ConfigVM>));
        }
        public void Get_by_existing_Id_returns_correct_item()
        {
            // Act
            var result      = _controller.Get(1);
            var typedResult = (result.Result as ObjectResult).Value;
            var data        = UnitTestExtensions.ExtractFromDataObject <EmployerVM>(typedResult);

            // assert
            Assert.IsInstanceOfType(data, typeof(EmployerVM));
            Assert.AreEqual(_fakeEmployer.ID, data.id);
        }
        public void Get_by_Id_existing_returns_correct_item()
        {
            // Act
            var result      = _controller.Get(1);
            var typedResult = (result.Result as ObjectResult).Value;
            var configVM    = UnitTestExtensions.ExtractFromDataObject <ConfigVM>(typedResult);

            // assert
            Assert.IsInstanceOfType(configVM, typeof(ConfigVM));
            Assert.AreEqual(_fakeConfig.ID, configVM.id);
        }
Exemplo n.º 9
0
        public void GetMany_with_existing_returns_all_records_of_type()
        {
            // Act
            var result            = _controller.Get().Result as ObjectResult;
            var resultHasDataProp = result?.Value.GetType().GetProperty("data") != null;
            var viewModelList     = UnitTestExtensions.ExtractFromDataObject <IEnumerable <WorkOrderVM> >(result?.Value);

            // Assert
            Assert.IsTrue(resultHasDataProp);
            Assert.IsTrue(viewModelList.Count() == _fakeWorOrderDTOList.Count);
            Assert.IsInstanceOfType(viewModelList, typeof(IEnumerable <WorkOrderVM>));
        }
Exemplo n.º 10
0
        public void Get_by_existing_Id_returns_correct_item_in_data_obj()
        {
            // Act
            var result       = _controller.Get("fakeReportName", DateTimeLocal(FAKETIMEZONE), DateTimeLocal(FAKETIMEZONE), 0).Result as ObjectResult;
            var data         = UnitTestExtensions.ExtractFromDataObject <List <dynamic> >(result?.Value);
            var singleRecord = data.FirstOrDefault();

            // assert
            Assert.IsInstanceOfType(data, typeof(List <dynamic>));
            Assert.AreEqual(singleRecord?.GetType().GetProperty("fakeData").GetValue(singleRecord, null), "fake AF");
            Assert.IsTrue(UnitTestExtensions.HasDataProperty(result));
        }
Exemplo n.º 11
0
        public void Post_valid_data_returns_new_record_in_data_object()
        {
            // arrange
            var validViewModel = new ScheduleRuleVM();
            // act
            var result            = _controller.Post(validViewModel).Result as ObjectResult;
            var returnedViewModel = UnitTestExtensions.ExtractFromDataObject <ScheduleRuleVM>(result?.Value);

            //assert
            Assert.IsInstanceOfType(returnedViewModel, typeof(ScheduleRuleVM));
            Assert.IsTrue(UnitTestExtensions.HasDataProperty(result));
        }
        public void ProfileGet_finds_employer_returns_profile()
        {
            // arrange
            ArrangeForEmployerFound();
            // act
            var result      = _controller.ProfileGet();
            var typedResult = (result.Result as ObjectResult).Value;
            var data        = UnitTestExtensions.ExtractFromDataObject <EmployerVM>(typedResult);

            // assert
            Assert.IsInstanceOfType(result.Result, typeof(OkObjectResult));
            Assert.IsTrue(data.email == "*****@*****.**");
        }
Exemplo n.º 13
0
        public void Post_valid_data_returns_new_record_in_data_oject()
        {
            // arrange
            var validViewModel = new LookupVM();
            // act
            var result            = _controller.Post(validViewModel).Result as ObjectResult;
            var returnedViewModel = UnitTestExtensions.ExtractFromDataObject <LookupVM>(result?.Value);
            var resultHasDataProp = result?.Value.GetType().GetProperty("data") != null;

            //assert
            Assert.IsInstanceOfType(returnedViewModel, typeof(LookupVM));
            Assert.IsTrue(resultHasDataProp);
        }
        public void GetMany_with_existing_returns_all_records_of_type()
        {
            // Act
            var result = _controller.Get(new ApiRequestParams()
            {
                pageNumber = 1, pageSize = 10
            });
            var typedResult     = (result.Result as ObjectResult).Value;
            var employersVMList = UnitTestExtensions.ExtractFromDataObject <IEnumerable <Service.DTO.EmployersList> >(typedResult);

            // Assert
            Assert.IsTrue(employersVMList.Count() == _fakeEmployers.Count);
            Assert.IsInstanceOfType(employersVMList, typeof(IEnumerable <Service.DTO.EmployersList>));
        }
Exemplo n.º 15
0
        public void Get_by_existing_Id_returns_correct_item()
        {
            // Arrange
            ArrangeClaimsPrincipalAndExistingEmployer();
            // Act
            var result            = _controller.Get(1).Result as ObjectResult;
            var data              = UnitTestExtensions.ExtractFromDataObject <WorkOrderVM>(result?.Value);
            var resultHasDataProp = result?.Value.GetType().GetProperty("data") != null;

            // assert
            Assert.IsTrue(resultHasDataProp);
            Assert.IsInstanceOfType(data, typeof(WorkOrderVM));
            Assert.AreEqual(_fakeWorkOrder.ID, data.id);
        }
Exemplo n.º 16
0
        public void Post_valid_data_returns_new_record_in_data_oject()
        {
            // arrange
            ArrangeClaimsPrincipalAndExistingEmployer();
            var validViewModel = new WorkOrderVM();
            // act
            var result            = _controller.Post(validViewModel).Result as ObjectResult;
            var returnedViewModel = UnitTestExtensions.ExtractFromDataObject <WorkOrderVM>(result?.Value);
            var resultHasDataProp = result?.Value.GetType().GetProperty("data") != null;

            //assert
            Assert.IsInstanceOfType(returnedViewModel, typeof(WorkOrderVM));
            Assert.IsTrue(resultHasDataProp);
        }
Exemplo n.º 17
0
        public void Get_Definition_by_existing_Id_returns_OkReponse()
        {
            // Arrange
            _reportsServ.Setup(r => r.Exists("fakeReportName"))
            .Returns(true);
            // Act
            var result = _controller.Get("fakeReportName").Result as ObjectResult;
            var data   = UnitTestExtensions.ExtractFromDataObject <ReportDefinitionVM>(result?.Value);

            // assert
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.IsInstanceOfType(data, typeof(ReportDefinitionVM));
            Assert.AreEqual(data.name, data.name);
            Assert.IsTrue(UnitTestExtensions.HasDataProperty(result));
        }
        public void ReportsController_Get_table_metadata_returns_Ok()
        {
            // arrange
            _reportsServ.Setup(s => s.GetColumns(ValidTableNames.Activities.ToString()))
            .Returns(new List <QueryMetadata>());
            // act
            var result            = _controller.Get(ValidTableNames.Activities.ToString());
            var typedResult       = (result as ObjectResult).Value;
            var data              = UnitTestExtensions.ExtractFromDataObject <List <QueryMetadata> >(typedResult);
            var resultHasDataProp = data != null;

            // assert
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.IsInstanceOfType(data, typeof(List <QueryMetadata>));
            Assert.IsTrue(resultHasDataProp);
        }
        public void Post_valid_data_returns_new_record_in_data_oject()
        {
            // arrange
            var validViewModel = new EmployerVM()
            {
                name = "Jimmy Hendrix"
            };
            // act
            var result            = _controller.Post(validViewModel);
            var typedResult       = (result.Result as ObjectResult).Value;
            var returnedViewModel = UnitTestExtensions.ExtractFromDataObject <EmployerVM>(typedResult);
            var resultHasDataProp = typedResult.GetType().GetProperty("data") != null;

            //assert
            Assert.IsInstanceOfType(returnedViewModel, typeof(EmployerVM));
            Assert.IsTrue(resultHasDataProp);
        }
Exemplo n.º 20
0
        public void Put_Returns_OKResult_when_valid_query_passed()
        {
            // Arrange
            _reportsServ.Setup(s => s.ValidateQuery(It.IsAny <string>()))
            .Returns(new List <string>());
            _reportsServ.Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(true);
            _reportsServ.Setup(s => s.Save(It.IsAny <ReportDefinition>(), It.IsAny <string>()))
            .Verifiable();
            // act
            var result           = _controller.Put("placeholder", new ReportDefinitionVM()).Result;
            var resultStatusCode = UnitTestExtensions.GetPrimitiveProp <int>(result, "StatusCode");

            // Assert
            Assert.IsInstanceOfType(result, typeof(ObjectResult));
            Assert.IsTrue((int)resultStatusCode == (int)HttpStatusCode.OK);
        }
Exemplo n.º 21
0
        public void Put_valid_data_returns_ok_result_and_updated_record()
        {
            // arrange
            var validViewModel = _mapper.Map <ScheduleRuleVM>(_fakeScheduleRule);

            validViewModel.id = 0;
            // act
            var result            = _controller.Put(1, validViewModel).Result as ObjectResult;
            var returnedViewModel = UnitTestExtensions.ExtractFromDataObject <ScheduleRuleVM>(result?.Value);

            //assert
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(_fakeScheduleRule, _savedScheduleRule);
            Assert.AreEqual(_fakeScheduleRule.day, _savedScheduleRule.day);
            Assert.IsInstanceOfType(returnedViewModel, typeof(ScheduleRuleVM));
            Assert.IsTrue(UnitTestExtensions.HasDataProperty(result));
        }
Exemplo n.º 22
0
        public async Task CompanionFail()
        {
            controller.StartTimeout = TimeSpan.FromSeconds(2);
            OnActivate = () => { throw new NotImplementedException(); };
            GetPlayer  = () => new Mockups.Vpaid();

            var adSource = new Mockups.AdSource()
            {
                Type = Guid.NewGuid().ToString()
            };
            var cancellationToken = new CancellationToken();
            var progress          = new Progress <AdStatus>();

            await UnitTestExtensions.ThrowsExceptionAsync <Exception>(async() => await controller.PlayAdAsync(adSource).AsTask(cancellationToken, progress));

            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);
        }
        public void Post_valid_data_returns_new_record_in_data_oject()
        {
            // arrange
            var validConfig = new ConfigVM()
            {
                key = "fakeOrgName", value = "Machete"
            };
            // act
            var result            = _controller.Post(validConfig);
            var typedResult       = (result.Result as ObjectResult).Value;
            var configVM          = UnitTestExtensions.ExtractFromDataObject <ConfigVM>(typedResult);
            var resultHasDataProp = typedResult.GetType().GetProperty("data") != null;

            //assert
            Assert.IsInstanceOfType(configVM, typeof(ConfigVM));
            Assert.IsTrue(resultHasDataProp);
            Assert.AreEqual("fakeOrgName", configVM.key);
        }
Exemplo n.º 24
0
        public async Task CancelPreload()
        {
            controller.StartTimeout = TimeSpan.FromSeconds(8);
            OnActivate = null;

            var adSource = GetLinearAdSource();

            var cts = new CancellationTokenSource();

            GetPlayer = () => new Mockups.Vpaid();
            var task = controller.PreloadAdAsync(adSource).AsTask(cts.Token);

            cts.Cancel();
            await UnitTestExtensions.ThrowsExceptionAsync <OperationCanceledException>(async() => await task);

            Assert.IsFalse(playerStack.Any());
            Assert.IsTrue(state == AdState.None);
        }
Exemplo n.º 25
0
        public void Put_valid_data_returns_ok_result_and_updated_record()
        {
            // arrange
            var validViewModel = _mapper.Map <WorkAssignmentVM>(_fakeWorkAssignment);

            validViewModel.id = 0;
            // act
            var result            = _controller.Put(1, validViewModel).Result as ObjectResult;
            var returnedViewModel = UnitTestExtensions.ExtractFromDataObject <WorkAssignmentVM>(result?.Value);

            //assert
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(_fakeWorkAssignment, _savedWorkAssignment);
            Assert.AreEqual(_fakeWorkAssignment.ID, _savedWorkAssignment.ID);
            Assert.AreEqual(_fakeWorkAssignment.hours, _savedWorkAssignment.hours);
            Assert.AreEqual(_fakeWorkAssignment.description, _savedWorkAssignment.description);
            Assert.IsInstanceOfType(returnedViewModel, typeof(WorkAssignmentVM));
            Assert.IsTrue(UnitTestExtensions.HasDataProperty(result));
        }
        public void Put_valid_data_returns_ok_result_and_updated_record()
        {
            // arrange
            var validViewModel = _mapper.Map <TransportProviderVM>(_fakeTransportProvider);

            validViewModel.id = 0;
            // act
            var result            = _controller.Put(1, validViewModel).Result as ObjectResult;
            var returnedViewModel = UnitTestExtensions.ExtractFromDataObject <TransportProviderVM>(result?.Value);

            //assert
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(_fakeTransportProvider, _savedTransportProvider);
            Assert.AreEqual(_fakeTransportProvider.ID, _savedTransportProvider.ID);
            Assert.AreEqual(_fakeTransportProvider.key, _savedTransportProvider.key);
            Assert.AreEqual(_fakeTransportProvider.text_EN, _savedTransportProvider.text_EN);
            Assert.IsInstanceOfType(returnedViewModel, typeof(TransportProviderVM));
            Assert.IsTrue(UnitTestExtensions.HasDataProperty(result));
        }
Exemplo n.º 27
0
        public void Put_valid_data_returns_ok_result_and_updated_record()
        {
            // arrange
            var validViewModel = _mapper.Map <LookupVM>(_fakeLookup);

            validViewModel.id = 0;
            // act
            var result            = _controller.Put(1, validViewModel);
            var parsedObject      = (result.Result as ObjectResult)?.Value;
            var returnedViewModel = UnitTestExtensions.ExtractFromDataObject <LookupVM>(parsedObject);
            var resultHasDataProp = parsedObject?.GetType().GetProperty("data") != null;

            //assert
            Assert.IsInstanceOfType(result?.Result, typeof(OkObjectResult));
            Assert.AreEqual(_fakeLookup, _savedLookup);
            Assert.AreEqual("blah", _savedLookup.key);
            Assert.IsInstanceOfType(returnedViewModel, typeof(LookupVM));
            Assert.IsTrue(resultHasDataProp);
        }
Exemplo n.º 28
0
        public void Put_Returns_500_when_serv_throws()
        {
            // Arrange
            _reportsServ.Setup(s => s.ValidateQuery(It.IsAny <string>()))
            .Returns(new List <string>());
            _reportsServ.Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(true);
            _reportsServ.Setup(s => s.Save(It.IsAny <ReportDefinition>(), It.IsAny <string>()))
            .Callback(() => throw new Exception());
            // act
            var result           = _controller.Put("placeholder", new ReportDefinitionVM()).Result;
            var resultStatusCode = UnitTestExtensions.GetPrimitiveProp <int>(result, "StatusCode");
            var value            = result.GetType().GetProperty("Value").GetValue(result, null);
            var typedErrors      = UnitTestExtensions.GetProp <Dictionary <string, List <string> > >(value, "errors");

            // Assert
            Assert.IsInstanceOfType(result, typeof(ObjectResult));
            Assert.IsTrue((int)resultStatusCode == (int)HttpStatusCode.InternalServerError);
            Assert.IsTrue(typedErrors.First().Value.First() == "Exception of type 'System.Exception' was thrown.");
        }
        public void Put_valid_data_returns_ok_result_and_updated_record()
        {
            // arrange
            var validViewModel = _mapper.Map <EmployerVM>(_fakeEmployer);

            validViewModel.id = 0;
            // act
            var result            = _controller.Put(1, validViewModel);
            var parsedObject      = (result.Result as ObjectResult)?.Value;
            var returnedViewModel = UnitTestExtensions.ExtractFromDataObject <EmployerVM>(parsedObject);
            var resultHasDataProp = parsedObject?.GetType().GetProperty("data") != null;

            //assert
            Assert.IsInstanceOfType(result.Result, typeof(OkObjectResult));
            Assert.AreEqual(_fakeEmployer, _savedEmployer);
            Assert.AreEqual("Jimmy Hendrix", _savedEmployer.name);
            Assert.AreEqual("123 Yellow Sub", _savedEmployer.address1);
            Assert.IsInstanceOfType(returnedViewModel, typeof(EmployerVM));
            Assert.IsTrue(resultHasDataProp);
        }
Exemplo n.º 30
0
        public void Create_Returns_OKResult_when_valid_query_passed()
        {
            // Arrange
            _reportsServ.Setup(s => s.ValidateQuery("validQuery"))
            .Returns(new List <string>());
            _reportsServ.Setup(s => s.Exists("reportWithValidQuery"))
            .Returns(false);
            _reportsServ.Setup(s => s.Create(It.IsAny <ReportDefinition>(), It.IsAny <string>()))
            .Returns(_fakeReport);
            // act
            var result = _controller.Create(new ReportDefinitionVM()
            {
                name     = "reportWithValidQuery",
                sqlquery = "validQuery"
            })
                         .Result;
            var resultStatusCode = UnitTestExtensions.GetPrimitiveProp <int>(result, "StatusCode");

            // Assert
            Assert.IsInstanceOfType(result, typeof(ObjectResult));
            Assert.IsTrue((int)resultStatusCode == (int)HttpStatusCode.Created);
        }