public void GetResultById_should_return_expected_result() { // given TestsClient client = Helpers.CreateTestsClient(); TestFile testFile = Helpers.CreateTestFileAndTest(client); var repository = ServiceStarter.Container.GetInstance <ITestFileResultRepository>(); var result1 = new TestFileResult() { StartTime = DateTime.Now, EndTime = DateTime.Now.AddSeconds(1), Filename = testFile.Filename }; var result2 = new TestFileResult() { StartTime = DateTime.Now, EndTime = DateTime.Now.AddSeconds(1), Filename = testFile.Filename }; repository.Add(result1).Wait(); repository.Add(result2).Wait(); // when TestFileResult actualResult = client.GetResultById(result2.Id); // then Assert.That(actualResult, Is.Not.Null); Assert.That(actualResult.Id, Is.EqualTo(result2.Id)); }
public void ReorderTests_should_change_ordering_of_tests_on_disk() { // given TestsClient client = Helpers.CreateTestsClient(); TestFile testFile = Helpers.CreateTestFileAndTest(client); var reorder = new List <TestPosition> { new TestPosition { OriginalPostion = 1 }, new TestPosition { OriginalPostion = 0 } }; // when bool success = client.ReorderTests(testFile.Filename, reorder); // then Assert.True(success); var updatedTestFile = client.GetTestFile(testFile.Filename); Assert.That(updatedTestFile.Tests.Count(), Is.EqualTo(2)); Assert.That(updatedTestFile.Variables.Count, Is.EqualTo(testFile.Variables.Count)); Assert.That(updatedTestFile.Tests.First().Description, Is.EqualTo(testFile.Tests.Skip(1).First().Description)); Assert.That(updatedTestFile.Tests.Skip(1).First().Description, Is.EqualTo(testFile.Tests.First().Description)); }
public void CreateTest_should_create_test_for_existing_file() { // given string filename = Helpers.GetJsonFilename(); TestsClient client = Helpers.CreateTestsClient(); client.CreateTestFile(new TestFile() { Filename = filename }); var test = new Test() { Assertions = new List <Assertion>(), AvailableVariables = new List <Variable>(), CapturedVariables = new List <CapturedVariable>(), Headers = new List <HeaderItem>(), Method = "POST", Url = "url" }; // when bool success = client.CreateTest(filename, test); // then string fullPath = Helpers.GetFullPath(filename); Assert.True(success); Assert.True(File.Exists(fullPath)); Assert.That(new FileInfo(fullPath).Length, Is.GreaterThan(0)); }
public void Setup() { _httpClient = new HttpClient(); _usersClient = new UsersClient(_httpClient); _testsClient = new TestsClient(_httpClient); _questionsClient = new QuestionsClient(_httpClient); _sut = new AnswersClient(_httpClient); _user = GetRandomUser(); _usersClient.RegisterUserAsync(_user).GetAwaiter().GetResult(); _testId = _testsClient.AddAsync().GetAwaiter().GetResult().Deserialize <Guid>(); for (var i = 0; i < 10; i++) { _questionsClient.AddAsync(_testId).GetAwaiter().GetResult(); } _questions = _questionsClient.GetListAsync(_testId).GetAwaiter().GetResult().Deserialize <List <QuestionDto> >(); foreach (var question in _questions) { question.Question = GetRandomString(); question.Answer = GetRandomString(); _questionsClient.UpdateAsync(question).GetAwaiter().GetResult(); } }
public void GetSummaries_should_return_all_results() { // given TestsClient client = Helpers.CreateTestsClient(); TestFile testFile = Helpers.CreateTestFileAndTest(client); var repository = ServiceStarter.Container.GetInstance <ITestFileResultRepository>(); var result1 = new TestFileResult() { StartTime = DateTime.Now, EndTime = DateTime.Now.AddSeconds(1), Filename = testFile.Filename }; var result2 = new TestFileResult() { StartTime = DateTime.Now, EndTime = DateTime.Now.AddSeconds(1), Filename = testFile.Filename }; repository.Add(result1).Wait(); repository.Add(result2).Wait(); // when TestFileResultSummaryCollection results = client.GetSummaries(It.IsAny <DateTime>()).Result; // then Assert.That(results.TotalFileResults, Is.EqualTo(2)); }
public void Setup() { _httpClient = new HttpClient(); _usersClient = new UsersClient(_httpClient); _sut = new TestsClient(_httpClient); _user = GetRandomUser(); _usersClient.RegisterUserAsync(_user).GetAwaiter().GetResult(); }
public void Setup() { _httpClient = new HttpClient(); _usersClient = new UsersClient(_httpClient); _testsClient = new TestsClient(_httpClient); _sut = new QuestionsClient(_httpClient); _user = GetRandomUser(); _usersClient.RegisterUserAsync(_user).GetAwaiter().GetResult(); _testId = _testsClient.AddAsync().GetAwaiter().GetResult().Deserialize <Guid>(); }
public async Task GetAll_WithoutAnyPosts_ReturnEmptyResponse() { // Arrange await AuthenticateAsync(); // Act var response = await TestsClient.GetAsync(ApiRoutes.Posts.GetAll); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); // HttpStatusCode.NotAcceptable (await response.Content.ReadAsAsync <List <Post> >()).Should().BeEmpty(); }
public void GetRawFile_should_return_expected_source() { // given TestsClient client = Helpers.CreateTestsClient(); TestFile testFile = Helpers.CreateTestFileAndTest(client); // when string rawFile = client.GetRawFile(testFile.Filename); // then Assert.That(rawFile, Is.Not.Null); Assert.That(rawFile, Is.StringContaining(@"""Tests"": [")); }
public void GetTestFile_should_return_expected_testfile() { // given TestsClient client = Helpers.CreateTestsClient(); TestFile testFile = Helpers.CreateTestFileAndTest(client); // when TestFile actualTestFile = client.GetTestFile(testFile.Filename); // then Assert.That(actualTestFile, Is.Not.Null); Assert.That(actualTestFile.Filename, Is.EqualTo(testFile.Filename)); Assert.That(actualTestFile.Tests.Count(), Is.EqualTo(2)); }
public void DeleteTest_should_save_changes_to_test() { // given TestsClient client = Helpers.CreateTestsClient(); TestFile expectedTestFile = Helpers.CreateTestFileAndTest(client); // when bool success = client.DeleteTest(0, expectedTestFile.Filename); // then TestFile actualTestFile = client.GetTestFile(expectedTestFile.Filename); Assert.True(success); Assert.That(actualTestFile.Tests.Count(), Is.EqualTo(1)); }
public void DeleteFile_should_delete_file_from_disk() { // given string filename = Helpers.GetJsonFilename(); TestsClient client = Helpers.CreateTestsClient(); TestFile testFile = Helpers.CreateTestFileAndTest(client); // when bool success = client.DeleteFile(testFile.Filename); // then string fullPath = Helpers.GetFullPath(filename); Assert.True(success); Assert.False(File.Exists(fullPath)); }
public void CopyTestFile_should_call_expected_web_method(bool expectedResult) { // given const string sourceFileName = "gotta love TDD"; const string targetFileName = "I said what what in the b..."; const string expectedServiceUrl = "I am a base url"; var client = new RestClientMock { RestResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = expectedResult.ToString().ToLower() } }; var clientFactory = new Mock <IRestSharpClientFactory>(); clientFactory .Setup(x => x.Create(expectedServiceUrl)) .Returns(client); // when var testsClient = new TestsClient(expectedServiceUrl, clientFactory.Object); bool result = testsClient.CopyTestFile(sourceFileName, targetFileName); // then Assert.That(result, Is.EqualTo(expectedResult)); IRestRequest request = client.RestRequest; Assert.That(request.Method, Is.EqualTo(Method.POST)); Assert.That(request.Resource, Is.EqualTo(TestsClient.RESOURCE_PATH + "/testfile/copy")); Assert.That(request.Parameters.Count, Is.EqualTo(2)); Parameter param1 = request.Parameters[0]; Assert.That(param1.Name, Is.EqualTo("sourceFileName")); Assert.That(param1.Type, Is.EqualTo(ParameterType.QueryString)); Assert.That(param1.Value, Is.EqualTo(sourceFileName)); Parameter param2 = request.Parameters[1]; Assert.That(param2.Name, Is.EqualTo("targetFileName")); Assert.That(param2.Type, Is.EqualTo(ParameterType.QueryString)); Assert.That(param2.Value, Is.EqualTo(targetFileName)); }
public void CopyTest_should_call_expected_web_method(bool expectedResult) { // given const string expectedServiceUrl = "some-url-init"; const int expectedPosition = 123; const string expectedFileName = "lalalala.txt"; var client = new RestClientMock { RestResponse = new RestResponse { StatusCode = HttpStatusCode.OK, Content = expectedResult.ToString().ToLower() } }; var clientFactory = new Mock <IRestSharpClientFactory>(); clientFactory .Setup(x => x.Create(expectedServiceUrl)) .Returns(client); // when var testsClient = new TestsClient(expectedServiceUrl, clientFactory.Object); bool result = testsClient.CopyTest(expectedPosition, expectedFileName); // then Assert.That(result, Is.EqualTo(expectedResult)); IRestRequest request = client.RestRequest; Assert.That(request.Method, Is.EqualTo(Method.POST)); Assert.That(request.Resource, Is.EqualTo(TestsClient.RESOURCE_PATH + "/test/copy")); Assert.That(request.Parameters.Count, Is.EqualTo(2)); Parameter param1 = request.Parameters[0]; Assert.That(param1.Name, Is.EqualTo("position")); Assert.That(param1.Type, Is.EqualTo(ParameterType.QueryString)); Assert.That(param1.Value, Is.EqualTo(expectedPosition.ToString())); Parameter param2 = request.Parameters[1]; Assert.That(param2.Name, Is.EqualTo("fileName")); Assert.That(param2.Type, Is.EqualTo(ParameterType.QueryString)); Assert.That(param2.Value, Is.EqualTo(expectedFileName)); }
public void UpdateTestFile_should_store_changes() { // given TestsClient client = Helpers.CreateTestsClient(); TestFile testFile = Helpers.CreateTestFileAndTest(client); testFile.Tests = new List <Test>(); // when bool success = client.UpdateTestVariables(testFile); // then Assert.True(success); TestFile actualTestFile = client.GetTestFile(testFile.Filename); Assert.That(actualTestFile.Tests.Count(), Is.EqualTo(2)); }
public void EditTest_should_save_changes_to_test_as_expected() { // given TestsClient client = Helpers.CreateTestsClient(); TestFile testFile = Helpers.CreateTestFileAndTest(client); Test expectedTest = testFile.Tests.FirstOrDefault(); expectedTest.Description = "new description"; // when bool success = client.EditTest(testFile.Filename, 0, expectedTest); // then TestFile actualTest = client.GetTestFile(testFile.Filename); Assert.True(success); Assert.That(actualTest.Tests.First().Description, Is.StringContaining("new description")); }
public static TestFile CreateTestFileAndTest(TestsClient client) { string filename = GetJsonFilename(); var test1 = new Test() { Assertions = new List <Assertion>(), AvailableVariables = new List <Variable>(), CapturedVariables = new List <CapturedVariable>(), Headers = new List <HeaderItem>(), Description = "short desc 1", Method = "POST", Url = "url 1" }; var test2 = new Test() { Assertions = new List <Assertion>(), AvailableVariables = new List <Variable>(), CapturedVariables = new List <CapturedVariable>(), Headers = new List <HeaderItem>(), Description = "short desc 2", Method = "POST", Url = "url 2" }; var testFile = new TestFile { Filename = filename }; client.CreateTestFile(testFile); client.CreateTest(filename, test1); client.CreateTest(filename, test2); var tests = new List <Test>() { test1, test2 }; testFile.Tests = tests; return(testFile); }
public void CreateTestFile_should_write_file() { // given string filename = Helpers.GetJsonFilename(); TestsClient client = Helpers.CreateTestsClient(); // when bool success = client.CreateTestFile(new TestFile() { Filename = filename }); // then string fullPath = Helpers.GetFullPath(filename); Assert.True(success); Assert.True(File.Exists(fullPath)); Assert.That(new FileInfo(fullPath).Length, Is.GreaterThan(0)); }
public void ListFiles_should_list_all_files() { // given string testFilepath1 = Helpers.GetFullPath(Helpers.GetJsonFilename()); File.WriteAllText(testFilepath1, @"ANY DATA1"); string testFilepath2 = Helpers.GetFullPath(Helpers.GetJsonFilename()); File.WriteAllText(testFilepath2, @"ANY DATA2"); TestsClient client = Helpers.CreateTestsClient(); // when IEnumerable <string> files = client.ListFiles(); // then Assert.That(files, Is.Not.Null); Assert.That(files.Count(), Is.EqualTo(2)); }
public async Task Get_ReturnsPosts_WhenExistsInTheDatabase() { // Arrange await AuthenticateAsync(); var createdPost = await CreatePostAsync(new CreatePostRequest { Name = "Test Post" }); // Act var response = await TestsClient .GetAsync(ApiRoutes.Posts.Get .Replace("{postId}", createdPost.Id.ToString())); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); var returnedPost = await response.Content.ReadAsAsync <Post>(); returnedPost.Id.Should().Be(createdPost.Id); returnedPost.Name.Should().Be("Test Post"); }
public void DeleteResultAsync_should_delete_expected_result() { // given TestsClient client = Helpers.CreateTestsClient(); TestFile testFile = Helpers.CreateTestFileAndTest(client); var repository = ServiceStarter.Container.GetInstance <ITestFileResultRepository>(); var result1 = new TestFileResult() { StartTime = DateTime.Now, EndTime = DateTime.Now.AddSeconds(1), Filename = testFile.Filename }; var result2 = new TestFileResult() { StartTime = DateTime.Now, EndTime = DateTime.Now.AddSeconds(1), Filename = testFile.Filename }; repository.Add(result1).Wait(); repository.Add(result2).Wait(); // when var result = client.DeleteResult(result2.Id); // then Assert.That(result, Is.True); TestFileResult deletedResult = client.GetResultById(result2.Id); Assert.That(deletedResult, Is.Null); TestFileResult otherResult = client.GetResultById(result1.Id); Assert.That(otherResult, Is.Not.Null); }
public static TestsClient CreateTestsClient() { var client = new TestsClient(ServiceStarter.BaseUrl, new RestSharpClientFactory()); return(client); }