public void IsValid_should_return_null_when_AssertionTypeValidation_value_is_null() { //given AssertionViewModel model = new AssertionViewModel { Description = string.Empty, Value = string.Empty }; // when var validationResult = IsValid(null, new ValidationContext(model)); // then Assert.Null(validationResult); }
public void BuildTestViewModel_should_return_correct_model_values_from_test() { // given const int testPosition = 1; _configurationServiceMock .Setup(x => x.GetScriptSnippetFilenames(ScriptSnippetType.BeforeExecute)) .Returns(new[] { "snippet1.snippet", "snippet2.snippet" }); List <Environment> environments = new List <Environment> { new Environment { Name = "Last", Order = 2 }, new Environment { Name = "First", Order = 0 } }; _environmentServiceMock .Setup(x => x.Get()) .Returns(environments); var expectedTest = new Test { Description = "Short Description", Url = "http://www.google.com", Method = MethodType.GET.ToString(), PostBody = "PostBody", ExpectedHttpStatusCode = HttpStatusCode.Accepted, Headers = new List <Syringe.Core.Tests.HeaderItem> { new Syringe.Core.Tests.HeaderItem() }, CapturedVariables = new List <CapturedVariable> { new CapturedVariable { Name = "CV-2" } }, Assertions = new List <Assertion> { new Assertion("Desc", "Val", AssertionType.Negative, AssertionMethod.CssSelector) }, ScriptSnippets = new ScriptSnippets() { BeforeExecuteFilename = "// this is some script" }, TestConditions = new TestConditions { RequiredEnvironments = new List <string> { "expected-env", "h3mang-and-d1cks" } } }; var testFile = new TestFile { Filename = "some file name...YURP", Tests = new List <Test> { new Test { CapturedVariables = new List <CapturedVariable> { new CapturedVariable("CV-1", "CV-1-Value") } }, expectedTest, new Test() }, Variables = new List <Variable> { new Variable("V-1", "V-1-Value", null) } }; // when TestViewModel actualModel = _mapper.BuildTestViewModel(testFile, testPosition); // then Assert.NotNull(actualModel); Assert.That(actualModel.Position, Is.EqualTo(testPosition)); Assert.That(actualModel.Description, Is.EqualTo(expectedTest.Description)); Assert.That(actualModel.Url, Is.EqualTo(expectedTest.Url)); Assert.That(actualModel.PostBody, Is.EqualTo(expectedTest.PostBody)); Assert.That(actualModel.Method, Is.EqualTo(MethodType.GET)); Assert.That(actualModel.ExpectedHttpStatusCode, Is.EqualTo(expectedTest.ExpectedHttpStatusCode)); Assert.That(actualModel.Filename, Is.EqualTo(testFile.Filename)); Assert.That(actualModel.CapturedVariables.Count, Is.EqualTo(1)); Assert.That(actualModel.Assertions.Count, Is.EqualTo(1)); Assert.That(actualModel.Headers.Count, Is.EqualTo(1)); AssertionViewModel assertionViewModel = actualModel.Assertions.FirstOrDefault(); Assert.That(assertionViewModel.Description, Is.EqualTo("Desc")); Assert.That(assertionViewModel.Value, Is.EqualTo("Val")); Assert.That(assertionViewModel.AssertionType, Is.EqualTo(AssertionType.Negative)); Assert.That(assertionViewModel.AssertionMethod, Is.EqualTo(AssertionMethod.CssSelector)); Assert.That(actualModel.AvailableVariables.Count, Is.EqualTo(3)); VariableViewModel capturedVar = actualModel.AvailableVariables.Find(x => x.Name == "CV-1"); Assert.That(capturedVar, Is.Not.Null); Assert.That(capturedVar.Value, Is.EqualTo("CV-1-Value")); capturedVar = actualModel.AvailableVariables.Find(x => x.Name == "CV-2"); Assert.That(capturedVar, Is.Not.Null); VariableViewModel testVariable = actualModel.AvailableVariables.Find(x => x.Name == "V-1"); Assert.That(testVariable, Is.Not.Null); Assert.That(testVariable.Value, Is.EqualTo("V-1-Value")); Assert.That(actualModel.BeforeExecuteScriptFilename, Is.EqualTo(expectedTest.ScriptSnippets.BeforeExecuteFilename)); Assert.That(actualModel.BeforeExecuteScriptSnippets.Count(), Is.EqualTo(2)); Assert.That(actualModel.RequiredEnvironments, Is.EqualTo(expectedTest.TestConditions.RequiredEnvironments)); Assert.That(actualModel.Environments, Is.EqualTo(new List <string> { "First", "Last" })); }