/// <summary> /// Get the catalog of supported test environments.May return any of the following canonical error codes:- INVALID_ARGUMENT - if the request is malformed- NOT_FOUND - if the environment type does not exist- INTERNAL - if an internal error occurred /// Documentation https://developers.google.com/testing/v1/reference/testEnvironmentCatalog/get /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Testing service.</param> /// <param name="environmentType">The type of environment that should be listed.Required</param> /// <param name="optional">Optional paramaters.</param> /// <returns>TestEnvironmentCatalogResponse</returns> public static TestEnvironmentCatalog Get(TestingService service, string environmentType, TestEnvironmentCatalogGetOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (environmentType == null) { throw new ArgumentNullException(environmentType); } // Building the initial request. var request = service.TestEnvironmentCatalog.Get(environmentType); // Applying optional parameters to the request. request = (TestEnvironmentCatalogResource.GetRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request TestEnvironmentCatalog.Get failed.", ex); } }
public async Task CalculateSomethingExceptionOutOfRangeTest(int min, int max, int a, int b, [Frozen] Mock <IRandomService> randomService, [Frozen] Mock <IExternalSleepyService> sleepy, [Frozen] Mock <IFactoryTestingModel> factoryTestingModel, [Frozen] Mock <IFactoryException> factoryException, TestingService sut) { //arrange var rnd = new Random(DateTime.Now.Millisecond); var actualRandomValue = rnd.Next(min, max); randomService.Setup(service => service.GenerateRandomValue(1, 1000)).Returns(actualRandomValue); sleepy.Setup(service => service.SleepForATime()).ReturnsAsync(true); factoryException.Setup(service => service.Create("Out of range")).Throws(new Exception("Out of range")); //act var exception = await Assert.ThrowsAsync <Exception>(async() => await sut.CalculateSomethingRandom(a, b)); //assert randomService.Verify(service => service.GenerateRandomValue(1, 1000), Times.AtLeastOnce); sleepy.Verify(service => service.SleepForATime(), Times.AtLeastOnce); factoryTestingModel.Verify(service => service.Empty(), Times.AtLeastOnce); factoryException.Verify(service => service.Create("Out of range"), Times.AtLeastOnce); Assert.NotNull(exception); Assert.IsType <Exception>(exception); Assert.Equal("Out of range", exception.Message); }
public static async Task MainAsync(TestingService tester) { await tester.Insert(); await tester.InsertNulls(); await tester.SelectAll(); }
static void Main(string[] args) { var connectionString = ConfigurationManager.ConnectionStrings["TestDb"].ConnectionString; var dbContextOptionsBuilder = new DbContextOptionsBuilder <TestDbContext>(); dbContextOptionsBuilder.UseSqlServer(connectionString); var testDbContext = new TestDbContext(dbContextOptionsBuilder.Options); var testingService = new TestingService(testDbContext); testingService.InsertTest(); testingService.SelectTest(); testingService.InsertTheNullable(); testingService.SelectTheNullable(); }
// Start a topic test. public async Task <ActionResult> TopicTest(int?id) { try { // I.Checks. // Check id. if (!int.TryParse(id.ToString(), out int intId)) { return(RedirectToAction("Index")); } // Get courseDTO object. TopicDTO topicDTO = await TopicService.GetAsync(intId); if (topicDTO == null) { return(RedirectToAction("Index")); } //Get courseDTO object. CourseDTO courseDTO = await CourseService.GetAsync(topicDTO.CourseId); if (courseDTO == null) { return(RedirectToAction("Index")); } // II. Set ViewBag properties. ViewBag.CourseName = courseDTO.CourseTitle; ViewBag.TopicName = topicDTO.TopicTitle; ViewBag.TopicId = intId; // III. AutoMapper Setup. var config = new MapperConfiguration(cfg => { cfg.CreateMap <QuestionDTO, UserQuestionAnswersViewModel>() .ForMember("Question", opt => opt.MapFrom(obj => obj.QuestionText)) .ForMember("AnswerType", opt => opt.MapFrom(obj => obj.AnswerType.AnswerTypeDescription)) .ForMember("AvailableUserAnswers", opt => opt.MapFrom(obj => obj.Answers)) .ForMember("QuestionWeight", opt => opt.MapFrom(obj => obj.QuestionWeight)) .ForMember(q => q.SelectedUserAnswers, option => option.Ignore()) .ForMember(q => q.PostedUserAnswers, option => option.Ignore()); cfg.CreateMap <AnswerDTO, UserAnswer>() .ForMember("Id", opt => opt.MapFrom(obj => obj.AnswerId)) .ForMember("Answer", opt => opt.MapFrom(obj => obj.AnswerText)) .ForMember("IsSelected", opt => opt.MapFrom(obj => obj.IsProper)); }); IMapper iMapper = config.CreateMapper(); // IV. Get data for a view. IList <QuestionDTO> source = await TestingService.GetRandomQuestionsForTopic(intId); IEnumerable <UserQuestionAnswersViewModel> topicTestQuestionList = iMapper.Map <IEnumerable <QuestionDTO>, IEnumerable <UserQuestionAnswersViewModel> >(source); // V. Set properties: TestQuetions, AllAnswers and UserAnswers. TestQuetions = topicTestQuestionList.ToList(); AllAnswers.Clear(); UserAnswers.Clear(); foreach (var item in topicTestQuestionList) { AllAnswers[item.QuestionId] = item.AvailableUserAnswers.ToList(); UserAnswers[item.QuestionId] = new List <UserAnswer>(); } // VI. Set Timer. TestPeriod = courseDTO.TimeToAnswerOneQuestion * topicTestQuestionList.Count(); StartTestTime = DateTime.Now; // VII. return(View(topicTestQuestionList)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task CalculateSomethingRandomValueTest(int min, int max, string operationType, int delta, int a, int b, TestingModel actual, [Frozen] Mock <IRandomService> randomService, [Frozen] Mock <IExternalSleepyService> sleepy, [Frozen] Mock <IFactoryTestingModel> factoryTestingModel, [Frozen] Mock <IAsyncExecutor> asyncExecutor, TestingService sut) { //arrange var rnd = new Random(DateTime.Now.Millisecond); var actualRandomValue = rnd.Next(min, max); randomService.Setup(service => service.GenerateRandomValue(1, 1000)).Returns(actualRandomValue); sleepy.Setup(service => service.SleepForATime()).ReturnsAsync(true); factoryTestingModel.Setup(service => service.Create(operationType, actualRandomValue, a + b + delta)) .Returns(actual); asyncExecutor.Setup(service => service.FromResult(actual)).ReturnsAsync(actual); //act var expected = await sut.CalculateSomethingRandom(a, b); //assert randomService.Verify(service => service.GenerateRandomValue(1, 1000), Times.AtLeastOnce); sleepy.Verify(service => service.SleepForATime(), Times.AtLeastOnce); factoryTestingModel.Verify(service => service.Empty(), Times.AtLeastOnce); factoryTestingModel.Verify(service => service.Create(operationType, actualRandomValue, a + b + delta), Times.AtLeastOnce); asyncExecutor.Verify(service => service.FromResult(actual)); expected.Should().BeEquivalentTo(actual); }
public async Task CalculateSomethingRandomSleepForATimeExceptionTest(int a, int b, [Frozen] Mock <IRandomService> randomService, [Frozen] Mock <IExternalSleepyService> sleepy, [Frozen] Mock <IFactoryException> factoryException, TestingService sut) { //arrange sleepy.Setup(service => service.SleepForATime()).ReturnsAsync(false); factoryException.Setup(service => service.Create()).Throws <Exception>(); //act var exception = await Assert.ThrowsAsync <Exception>(async() => await sut.CalculateSomethingRandom(a, b)); //assert randomService.Verify(service => service.GenerateRandomValue(1, 1000)); sleepy.Verify(service => service.SleepForATime(), Times.AtLeastOnce); factoryException.Verify(service => service.Create(), Times.AtLeastOnce); Assert.NotNull(exception); Assert.IsType <Exception>(exception); Assert.Equal("Exception of type 'System.Exception' was thrown.", exception.Message); }