예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #4
0
        private static async Task <Dictionary <string, object> > GetPromptResults(string originPath)
        {
            var prompts = await PromptReader
                          .GetPromptsFromFile(originPath)
                          .ConfigureAwait(false);

            return(ConsolePromptReader.WritePrompts(prompts.ToList()));
        }
        public async Task GivenAnEmptyString_WhenGetPromptsFromFileIsCalled_ThenAnArgumentExceptionIsThrown()
        {
            //arrange

            //act
            await Assert.ThrowsAsync <ArgumentException>(
                () => PromptReader.GetPromptsFromFile(string.Empty))
            .ConfigureAwait(false);

            //assert
        }
        public async Task GivenAJsonFileWithMultipleValidPrompts_AndADifferentFilename_WhenGetPromptsFromFileIsCalled_ThenAFileNotFoundExceptionWillBeThrown()
        {
            //arrange
            var          filename   = Guid.NewGuid().ToString();
            var          file       = Path.Join(TempPath, filename);
            const string jsonString = VALID_MULTIPLE_PROMPTS;
            await File.WriteAllTextAsync(file, jsonString).ConfigureAwait(false);

            //act
            await Assert.ThrowsAsync <FileNotFoundException>(
                () => PromptReader.GetPromptsFromFile(TempPath))
            .ConfigureAwait(false);
        }
        public void GivenAnJsonStringWithNoPromptType_WhenGetPromptsFromStringIsCalled_ThenTheResultWillThrowAJsonException()
        {
            //arrange
            const string jsonString = @"
[
	{
		""promptType"": """",
		""id"": ""BooleanPromptId"",
		""message"": ""Boolean Prompt Message""
	}
]";

            //act
            Assert.Throws <JsonException>(() => PromptReader.GetPromptsFromString(jsonString));
        }
예제 #8
0
        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 async Task GivenAJsonStringWithAPromptWithAWhenArray_WhenGetPromptsFromFileIsCalled_ThenTheResultPromptWillHaveTheGivenWhenArray(object value, string jsonValue)
        {
            //arrange
            var expectedWhen = new PromptWhen
            {
                Id = "question",
                Is = value
            };
            var expectedPrompt = new TemplatePrompt
            {
                Id           = "BooleanPromptId",
                Message      = "Boolean Prompt Message",
                DefaultValue = false,
                When         = new List <PromptWhen>
                {
                    expectedWhen
                }
            };
            var jsonString = @"
[
	{
		""promptType"": ""Boolean"",
		""id"": ""BooleanPromptId"",
		""message"": ""Boolean Prompt Message"",
		""when"": [{
			""id"": ""question"",
			""is"": "             + jsonValue + @"
		}]
	}
]";
            await File.WriteAllTextAsync(TempFile, jsonString).ConfigureAwait(false);

            //act
            var result = await PromptReader.GetPromptsFromFile(TempPath).ConfigureAwait(false);

            //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 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 async Task GivenAJsonFileWithMultipleValidPrompts_WhenGetPromptsFromFileIsCalled_ThenTheResultWillHaveTheCorrentAmountsOfPrompts()
        {
            //arrange
            const int    expectedCount       = 6;
            const int    expectedStringCount = 2;
            const int    expectedIntCount    = 3;
            const string jsonString          = VALID_MULTIPLE_PROMPTS;
            await File.WriteAllTextAsync(TempFile, jsonString).ConfigureAwait(false);

            //act
            var actual = await PromptReader.GetPromptsFromFile(TempPath)
                         .ConfigureAwait(false);

            //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 async Task GivenAJsonFileWithNoMessage_WhenGetPromptsFromFileIsCalled_ThenTheResultWillThrowAValidationException()
        {
            //arrange
            const string jsonString = @"
[
	{
		""promptType"": ""Boolean"",
		""id"": ""BooleanPromptId"",
		""message"": """"
	}
]";
            await File.WriteAllTextAsync(TempFile, jsonString).ConfigureAwait(false);

            //act
            await Assert.ThrowsAsync <ValidationException>(
                () => PromptReader.GetPromptsFromFile(TempPath))
            .ConfigureAwait(false);

            //assert
        }
 public void GivenAnEmptyString_WhenGetPromptsFromStringIsCalled_ThenAnArgumentExceptionIsThrown()
 {
     Assert.Throws <ArgumentException>(() => PromptReader.GetPromptsFromString(string.Empty));
 }