public async Task Run_StartIntent_ReturnsAudioPlayerResult(string requestFile) { // Arrange var root = TestCompositionRoot.Create(); var requestData = root.WithInputFile($"alexa_bedtime.tests.TestData.Requests.{requestFile}"); var request = root.WithPostRequest(requestData); var logger = root.Get <ILogger>(); // Act var result = await WhiteNoiseFunction.Run(request, logger); // Assert Assert.IsType <OkObjectResult>(result); var resultData = result.Value <AlexaResponse>(); Assert.Equal("1.0", resultData.version); Assert.True(resultData.response.shouldEndSession); Assert.Single(resultData.response.directives); var playDirective = resultData.response.directives[0]; Assert.Equal("AudioPlayer.Play", playDirective.type); Assert.Equal("REPLACE_ALL", playDirective.playBehavior); Assert.Equal("0", playDirective.audioItem.stream.token); Assert.Equal(0, playDirective.audioItem.stream.offsetInMilliseconds); Assert.Equal("https://alexabedtime.blob.core.windows.net/sounds/10-hours-rain-96bps.mp3", playDirective.audioItem.stream.url); AssertRequestIsLogged(root); }
public async Task Run_StopIntent_ReturnsStopResult(string requestFile) { // Arrange var root = TestCompositionRoot.Create(); var requestData = root.WithInputFile($"alexa_bedtime.tests.TestData.Requests.{requestFile}"); var request = root.WithPostRequest(requestData); var logger = root.Get <ILogger>(); // Act var result = await WhiteNoiseFunction.Run(request, logger); // Assert Assert.IsType <OkObjectResult>(result); var resultData = result.Value <AlexaResponse>(); Assert.Equal("1.1", resultData.version); Assert.True(resultData.response.shouldEndSession); Assert.Equal("Simple", resultData.response.card.type); Assert.Equal("Bedtime", resultData.response.card.title); Assert.Equal("Enjoy your day!", resultData.response.card.content); var playDirective = resultData.response.directives[0]; Assert.Equal("AudioPlayer.Stop", playDirective.type); }
public void Render_ValidRecipe_ShowsRecipe() { // Given var root = TestCompositionRoot.Create(); root.WithRecipe("recipe-one", id: "my-identifier", category: "category-one", servings: 1, ingredients: "some food", directions: "what to do", source: "where it came from"); // When var page = root.GetComponent <Detail>(new Dictionary <string, object> { { "RecipeId", "my-identifier" } }); // Then Assert.Equal("my-identifier", page.Instance.Data.Id); Assert.Equal("recipe-one", page.Instance.Data.Name); Assert.Equal("category-one", page.Instance.Data.Category); Assert.Equal(1, page.Instance.Data.Servings); Assert.Equal("some food", page.Instance.Data.IngredientsRaw); Assert.Equal("what to do", page.Instance.Data.DirectionsRaw); Assert.Equal("where it came from", page.Instance.Data.Source); }
public void Get_NoSpecificRequest_ReturnsAllPersons() { // Arrange var root = TestCompositionRoot.Create(); root.WithPerson(firstName: "the-test", lastName: "writer"); root.WithPerson(firstName: "the-test", lastName: "reviewer"); var controller = root.Get <PersonController>(); // Act var response = controller.Get(); // Assert Assert.NotNull(response); Assert.IsType <OkObjectResult>(response); var result = response.CastValue <ICollection <Application.Models.Person> >(); Assert.Equal(2, result.Count); Assert.Equal("the-test", result.First().FirstName); Assert.Equal("writer", result.First().LastName); Assert.Equal("the-test writer", result.First().FullName); Assert.Equal("the-test", result.Last().FirstName); Assert.Equal("reviewer", result.Last().LastName); Assert.Equal("the-test reviewer", result.Last().FullName); }
public void Get_WithValidId_ReturnsMatchingPerson() { // Arrange var root = TestCompositionRoot.Create(); root.WithPerson(firstName: "the-test", lastName: "writer"); var person2 = root.WithPerson(firstName: "the-test", lastName: "reviewer", alias: "my-alias"); root.WithIdentity(alias: "my-alias", emailAddress: "*****@*****.**"); var controller = root.Get <PersonController>(); // Act var response = controller.Get(person2.Id); // Assert Assert.NotNull(response); Assert.IsType <OkObjectResult>(response); var result = response.CastValue <Application.Models.Person>(); Assert.Equal("the-test", result.FirstName); Assert.Equal("reviewer", result.LastName); Assert.Equal("*****@*****.**", result.EmailAddress); Assert.Equal("the-test reviewer", result.FullName); }
public void Post_WithPersonData_CreatesNewPerson() { // Arrange var root = TestCompositionRoot.Create(); root.WithPerson(firstName: "the-test", lastName: "writer"); var controller = root.Get <PersonController>(); var toPost = new Application.Models.Person { FirstName = "new-user", LastName = "created", BirthDate = DateTime.Today.AddDays(-1) }; // Act var response = controller.Post(toPost); // Assert Assert.NotNull(response); Assert.IsType <OkObjectResult>(response); var peopleResponse = controller.Get(); var result = peopleResponse.CastValue <ICollection <Application.Models.Person> >(); Assert.Equal(2, result.Count); }
public async Task GetAll_CriteriaAndCategory_ReturnsRecipesMatchingBoth() { // Given var root = TestCompositionRoot.Create(); root.WithRecipe("recipe-one", category: "cat-1"); root.WithRecipe("recipe-two", category: "something-else"); root.WithRecipe("recipe-three", category: "cat-1"); var api = root.Get <RecipeFunction>(); var request = root.GetRequest() .WithSearchCriteriaParameter("recipe") .WithCategoryParameter("cat-1"); // When var result = await api.GetAll(request, root.CoreLogger(), root.AuthenticatedUser()); // Then var data = result.AssertIsOkResultWithValue <IReadOnlyList <Recipe> >(); Assert.Equal(2, data.Count); Assert.Contains("recipe-one", data.Select(r => r.Name)); Assert.Contains("recipe-three", data.Select(r => r.Name)); }
public async Task Get_IdExists_ReturnsItem() { // Given var root = TestCompositionRoot.Create(); root.WithRecipe("recipe-one"); var recipe2Id = root.WithRecipe("recipe-two", "something to add", directions: "what to do", servings: 1, source: "the-test", rating: 3, category: "the-category"); var api = root.Get <RecipeFunction>(); // When var result = await api.GetItem(root.GetRequest(), recipe2Id, root.CoreLogger(), root.AuthenticatedUser()); // Then var data = result.AssertIsOkResultWithValue <Recipe>(); Assert.False(string.IsNullOrWhiteSpace(data.Id)); Assert.Equal("recipe-two", data.Name); Assert.Equal("something to add", data.Ingredients); Assert.Equal("what to do", data.Directions); Assert.Equal(1, data.Servings); Assert.Equal("the-test", data.Source); Assert.Equal(3, data.Rating); Assert.Equal("the-category", data.Category); }
public async Task Update_UnAuthenticatdUserValidRecipe_ReturnsForbidden() { // Given var root = TestCompositionRoot.Create(); root.WithRecipe(id: "the-identifier", name: "the-old-name"); var api = root.Get <RecipeFunction>(); var postData = new Recipe { Id = "the-identifier", Name = "the-new-item", Ingredients = "something to add", Directions = "what to do", Servings = 1, Source = "the-test", Rating = 3, Category = "the-category" }; // When var updateResult = await api.Update(root.PutRequest(postData), root.CoreLogger(), root.AuthenticatedUser()); // Then Assert.IsAssignableFrom <ForbidResult>(updateResult); }
public static TestCompositionRoot TestRoot(this ScenarioContext context) { if (!context.ContainsKey("TestCompositionRoot")) { context.Set(TestCompositionRoot.Create(), "TestCompositionRoot"); } return(context.Get <TestCompositionRoot>("TestCompositionRoot")); }
public async Task Delete_UnAuthenticatdUserValidRecipe_ReturnsForbidden() { // Given var root = TestCompositionRoot.Create(); root.WithRecipe(id: "the-identifier", name: "the-old-name"); var api = root.Get <RecipeFunction>(); // When var deleteResult = await api.Delete(root.DeleteRequest(), "the-identifier", root.CoreLogger(), root.AuthenticatedUser()); // Then Assert.IsAssignableFrom <ForbidResult>(deleteResult); }
public void Render_InvalidRecipe_ShowsNotFound() { // Given var root = TestCompositionRoot.Create(); // When var page = root.GetComponent <Detail>(new Dictionary <string, object> { { "RecipeId", "my-identifier" } }); // Then Assert.Null(page.Instance.Data.Id); Assert.Equal("Not Found", page.Instance.Data.Name); }
public void Get_WithInValidId_ReturnsNotFound() { // Arrange var root = TestCompositionRoot.Create(); root.WithPerson(firstName: "the-test", lastName: "writer"); var controller = root.Get <PersonController>(); // Act var response = controller.Get(250); // Assert Assert.NotNull(response); Assert.IsType <NotFoundResult>(response); }
public void Render_ShowsAllCategories() { // Given var root = TestCompositionRoot.Create() .WithCategory("one") .WithCategory("two"); // When var page = root.GetComponent <recipebook.blazor.Components.Search>(); // Then var categoryNames = page.Instance.Categories.Select(c => c.Name); Assert.Contains("one", categoryNames); Assert.Contains("two", categoryNames); }
public void Get_WithId_ReturnsSpecificValue() { // Arrange var root = TestCompositionRoot.Create(); var controller = root.Get <ValuesController>(); // Act var response = controller.Get(42); // Assert Assert.NotNull(response); Assert.Equal((int)HttpStatusCode.OK, response.StatusCode); var result = response.CastValue <string>(); Assert.Equal("value", result); }
public void Get_NoSpecificRequest_ReturnsValues() { // Arrange var root = TestCompositionRoot.Create(); var controller = root.Get <ValuesController>(); // Act var response = controller.Get(); // Assert Assert.NotNull(response); Assert.Equal((int)HttpStatusCode.OK, response.StatusCode); var result = response.CastValue <ICollection <string> >(); Assert.Equal(new[] { "value1", "value2" }, result); }
public async Task GetAll_NoParameters_ReturnsAll() { // Given var root = TestCompositionRoot.Create(); root.WithRecipe("recipe-one"); root.WithRecipe("recipe-two"); var api = root.Get <RecipeFunction>(); // When var result = await api.GetAll(root.GetRequest(), root.CoreLogger(), root.AuthenticatedUser()); // Then var data = result.AssertIsOkResultWithValue <IReadOnlyList <Recipe> >(); Assert.Equal(2, data.Count); }
public async Task Run_AuthenticatedUser_ReturnsUserData() { // Given var root = TestCompositionRoot.Create(); root.WithAuthenticatedUser("the-user"); var api = root.Get <UserFunction>(); // When var result = await api.Run(root.GetRequest(), root.CoreLogger(), root.AuthenticatedUser()); // Then var userResult = result.AssertIsOkResultWithValue <User>(); Assert.Equal("the-user", userResult.Name); Assert.NotEmpty(userResult.Claims); Assert.True(userResult.IsAuthenticated); }
public void Render_ShowsEmptyRecipe() { // Given var root = TestCompositionRoot.Create(); // When var page = root.GetComponent <Create>(); // Then Assert.Null(page.Instance.Data.Id); Assert.Null(page.Instance.Data.Name); Assert.Null(page.Instance.Data.Category); Assert.Null(page.Instance.Data.Servings); Assert.Null(page.Instance.Data.IngredientsRaw); Assert.Empty(page.Instance.Data.Ingredients); Assert.Null(page.Instance.Data.DirectionsRaw); Assert.Empty(page.Instance.Data.Directions); Assert.Null(page.Instance.Data.Source); }
public async Task Run_NoInputs_ReturnsApplicationData() { // Given var root = TestCompositionRoot.Create(); var api = root.Get <HealthFunction>(); // When var result = await api.Run(root.GetRequest(), root.CoreLogger(), root.AuthenticatedUser()); // Then var healthResult = result.AssertIsOkResultWithValue <ApplicationHealth>(); Assert.True(!string.IsNullOrWhiteSpace(healthResult.Version)); Assert.InRange(healthResult.CurrentDateTime, DateTime.Today, DateTime.Today.AddDays(1)); Assert.True(healthResult.Status); Assert.NotEmpty(healthResult.DependencyStatus); }
public async Task Search_ShowsSearchResults() { // Given var root = TestCompositionRoot.Create() .WithRecipe("recipe one") .WithRecipe("recipe two"); var page = root.GetComponent <recipebook.blazor.Components.Search>(); // When await page.Instance.SearchAsync(); // Then var appState = root.Get <AppState>(); Assert.Equal(2, appState.SearchResults.Count); Assert.Equal(new List <string> { "recipe one", "recipe two" }, appState.SearchResults.Select(r => r.Name).ToList()); }
public async Task Run_GetRequest_ReturnsAllCategories() { // Given var root = TestCompositionRoot.Create(); root.WithCategory("category-one"); root.WithCategory("category-two"); var function = root.Get <CategoryFunction>(); // When var result = await function.Run(root.GetRequest(), root.CoreLogger(), root.AuthenticatedUser()); //Then var resultData = result.AssertIsOkResultWithValue <IReadOnlyCollection <Category> >(); Assert.NotEmpty(resultData); Assert.Contains("category-one", resultData.Select(r => r.Name)); Assert.Contains("category-two", resultData.Select(r => r.Name)); }
public async Task Create_NameInput_CreatesCategory() { // Given var root = TestCompositionRoot.Create(); var function = root.Get <CategoryFunction>(); var data = new Category { Name = "one-to-add" }; var request = root.PostRequest(data); // When var result = await function.Create(request, root.CoreLogger(), root.AuthenticatedUser()); //Then var resultData = result.AssertIsOkResultWithValue <Category>(); Assert.NotNull(resultData); Assert.Contains("one-to-add", resultData.Name); }
public async Task GetAll_Criteria_ReturnsRecipesMatchingName(string searchCriteria) { // Given var root = TestCompositionRoot.Create(); root.WithRecipe("recipe-one", category: "cat-1"); root.WithRecipe("recipe-two", category: "cat-2"); var api = root.Get <RecipeFunction>(); var request = root.GetRequest() .WithSearchCriteriaParameter(searchCriteria); // When var result = await api.GetAll(request, root.CoreLogger(), root.AuthenticatedUser()); // Then var data = result.AssertIsOkResultWithValue <IReadOnlyList <Recipe> >(); Assert.Equal(1, data.Count); Assert.Equal("recipe-two", data[0].Name); }
public async Task Update_AuthenticatdUserValidRecipe_SuccessfullySaves() { // Given var root = TestCompositionRoot.Create(); root.WithAuthenticatedUser("the-user"); root.WithRecipe(id: "the-identifier", name: "the-old-name"); var api = root.Get <RecipeFunction>(); var postData = new Recipe { Id = "the-identifier", Name = "the-new-item", Ingredients = "something to add", Directions = "what to do", Servings = 1, Source = "the-test", Rating = 3, Category = "the-category" }; // When var updateResult = await api.Update(root.PutRequest(postData), root.CoreLogger(), root.AuthenticatedUser()); // Then var getResult = await api.GetAll(root.GetRequest(), root.CoreLogger(), root.AuthenticatedUser()); var getData = getResult.AssertIsOkResultWithValue <ICollection <Recipe> >(); var matchingResult = getData.SingleOrDefault(r => r.Name == "the-new-item"); Assert.NotNull(matchingResult); Assert.Equal("the-identifier", matchingResult.Id); Assert.Equal("something to add", matchingResult.Ingredients); Assert.Equal("what to do", matchingResult.Directions); Assert.Equal(1, matchingResult.Servings); Assert.Equal("the-test", matchingResult.Source); Assert.Equal(3, matchingResult.Rating); Assert.Equal("the-category", matchingResult.Category); }
public async Task Delete_AuthenticatedUserValidRecipe_RecipeDoesNoShowInSearchResults() { // Given var root = TestCompositionRoot.Create(); root.WithAuthenticatedUser("the-user"); root.WithRecipe(id: "the-identifier", name: "the-old-name"); var api = root.Get <RecipeFunction>(); // When var deleteResult = await api.Delete(root.DeleteRequest(), "the-identifier", root.CoreLogger(), root.AuthenticatedUser()); // Then Assert.IsAssignableFrom <OkResult>(deleteResult); var getResult = await api.GetAll(root.GetRequest(), root.CoreLogger(), root.AuthenticatedUser()); var getData = getResult.AssertIsOkResultWithValue <ICollection <Recipe> >(); Assert.DoesNotContain("the-identifier", getData.Select(r => r.Id).ToList()); }
public void Delete_WithInValidId_ReturnsNotFound() { // Arrange var root = TestCompositionRoot.Create(); root.WithPerson(firstName: "the-test", lastName: "writer"); root.WithPerson(firstName: "the-test", lastName: "reviewer"); var controller = root.Get <PersonController>(); // Act var response = controller.Delete(250); // Assert Assert.NotNull(response); Assert.IsType <NotFoundResult>(response); var peopleResponse = controller.Get(); var peopleResult = peopleResponse.CastValue <ICollection <Application.Models.Person> >(); Assert.Equal(2, peopleResult.Count); }
public void Delete_WithValidId_DeletesMatchingPerson() { // Arrange var root = TestCompositionRoot.Create(); root.WithPerson(firstName: "the-test", lastName: "writer"); var person2 = root.WithPerson(firstName: "the-test", lastName: "reviewer"); var controller = root.Get <PersonController>(); // Act var response = controller.Delete(person2.Id); // Assert Assert.NotNull(response); Assert.IsType <OkResult>(response); var peopleResponse = controller.Get(); var peopleResult = peopleResponse.CastValue <ICollection <Application.Models.Person> >(); Assert.Equal(1, peopleResult.Count); Assert.Equal("writer", peopleResult.First().LastName); }