public void GivenAnJsonStringWithValidBooleanProperties_AndAStringDefaultValueOfFalse_WhenGetPromptsFromStringIsCalled_ThenTheResultWillContainASingleValidBooleanPromptObject_WithDefaultValueSetToFalse() { //arrange const int expectedCount = 1; var expectedObject = new TemplatePrompt { PromptType = PromptType.Boolean, Id = "BooleanPromptId", Message = "Boolean Prompt Message", DefaultValue = false }; const string jsonString = @" [ { ""promptType"": ""Boolean"", ""id"": ""BooleanPromptId"", ""message"": ""Boolean Prompt Message"", ""defaultValue"": ""false"" } ]"; //act var result = PromptReader.GetPromptsFromString(jsonString); //assert AssertBooleanPromptEquality(expectedCount, expectedObject, result); }
public void GivenAnJsonStringWithValidIntProperties_AndAIntDefaultValueOfOne_WhenGetPromptsFromStringIsCalled_ThenTheResultWillContainASingleValidIntPromptObject_WithDefaultValueSetToOne() { //arrange const int expectedCount = 1; var expectedObject = new TemplatePrompt { PromptType = PromptType.Int, Id = "IntegerPromptId", Message = "Integer Prompt Message", DefaultValue = 1 }; const string jsonString = @" [ { ""promptType"": ""Int"", ""id"": ""IntegerPromptId"", ""message"": ""Integer Prompt Message"", ""defaultValue"": 1 } ]"; //act var result = PromptReader.GetPromptsFromString(jsonString); //assert AssertIntPromptEquality(expectedCount, expectedObject, result); }
public void GivenAnJsonStringWithValidStringProperties_AndAnIntDefaultValue_WhenGetPromptsFromStringIsCalled_ThenTheResultWillContainASingleStringPromptObject_WithTheIntDefaultValueSet() { //arrange const int expectedCount = 1; var expectedObject = new TemplatePrompt { PromptType = PromptType.String, Id = "StringPromptId", Message = "String Prompt Message", DefaultValue = "123" }; const string jsonString = @" [ { ""promptType"": ""String"", ""id"": ""StringPromptId"", ""message"": ""String Prompt Message"", ""defaultValue"": 123 } ]"; //act var result = PromptReader.GetPromptsFromString(jsonString); //assert AssertStringPromptEquality(expectedCount, expectedObject, result); }
public void GivenAnJsonStringWithNoPromptType_WhenGetPromptsFromStringIsCalled_ThenTheResultWillThrowAJsonException() { //arrange const string jsonString = @" [ { ""promptType"": """", ""id"": ""BooleanPromptId"", ""message"": ""Boolean Prompt Message"" } ]"; //act Assert.Throws <JsonException>(() => PromptReader.GetPromptsFromString(jsonString)); }
public void GivenAnJsonStringWithValidBooleanProperties_AndAnInvalidNumberDefaultValue_WhenGetPromptsFromStringIsCalled_ThenTheResultWillThrowAFormatException() { //arrange const string jsonString = @" [ { ""promptType"": ""Boolean"", ""id"": ""BooleanPromptId"", ""message"": ""Boolean Prompt Message"", ""defaultValue"": 123 } ]"; //act Assert.Throws <ValidationException>(() => PromptReader.GetPromptsFromString(jsonString)); }
public void GivenAnJsonStringWithMultipleValidPrompts_WhenGetPromptsFromStringIsCalled_ThenTheResultWillHaveTheCorrentAmountsOfPrompts() { //arrange const int expectedCount = 6; const int expectedStringCount = 2; const int expectedIntCount = 3; const string jsonString = MULTIPLE_VALID_PROMPTS; //act var actual = PromptReader.GetPromptsFromString(jsonString); //assert Assert.Equal(expectedCount, actual.Count()); Assert.Single(actual.Where(e => e.PromptType == PromptType.Boolean)); Assert.Equal(expectedStringCount, actual.Count(e => e.PromptType == PromptType.String)); Assert.Equal(expectedIntCount, actual.Count(e => e.PromptType == PromptType.Int)); }
public void GivenAJsonStringWithAPromptWithAWhenArray_WhenGetPromptsFromStringIsCalled_ThenTheResultPromptWillHaveTheGivenWhenArray() { //arrange var expectedWhen = new PromptWhen { Id = "question", Is = "123" }; var expectedPrompt = new TemplatePrompt { Id = "BooleanPromptId", Message = "Boolean Prompt Message", DefaultValue = false, When = new List <PromptWhen> { expectedWhen } }; const string jsonString = @" [ { ""promptType"": ""Boolean"", ""id"": ""BooleanPromptId"", ""message"": ""Boolean Prompt Message"", ""when"": [{ ""id"": ""question"", ""is"": ""123"" }] } ]"; //act var result = PromptReader.GetPromptsFromString(jsonString); //assert Assert.Single(result); var actualPrompt = result.First(); Assert.Equal(expectedPrompt.When.Count, actualPrompt.When.Count); var actualWhen = actualPrompt.When[0]; Assert.Equal(expectedWhen.Id, actualWhen.Id); Assert.Equal(expectedWhen.Is, actualWhen.Is); }
public void GivenAnEmptyString_WhenGetPromptsFromStringIsCalled_ThenAnArgumentExceptionIsThrown() { Assert.Throws <ArgumentException>(() => PromptReader.GetPromptsFromString(string.Empty)); }