Beispiel #1
0
        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 <Edit>(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 static void WithWorkItem(this TestCompositionRoot root,
                                        string type,
                                        string title,
                                        string areaPath,
                                        string status,
                                        string assignedTo    = "someone",
                                        DateTime?updatedAt   = null,
                                        DateTime?createdAt   = null,
                                        DateTime?activatedAt = null,
                                        DateTime?resolvedAt  = null,
                                        DateTime?closedAt    = null,
                                        string organization  = "jrolstad",
                                        string project       = "the-project")
        {
            var workItem = new TestContext.WorkItemData
            {
                Id           = Guid.NewGuid().ToString(),
                Title        = title,
                AreaPath     = areaPath,
                State        = status,
                AssignedTo   = assignedTo,
                UpdatedAt    = updatedAt ?? DateTime.Now,
                CreatedAt    = createdAt ?? DateTime.Now.AddDays(-1),
                ActivatedAt  = activatedAt,
                ResolvedAt   = resolvedAt,
                ClosedAt     = closedAt,
                WorkItemType = type
            };

            WithItem(organization, project, root.Context.WorkItems, workItem);
        }
        public static void WithReleaseEnvironment(this TestCompositionRoot root,
                                                  string name,
                                                  string releaseName,
                                                  string status,
                                                  DateTime?deployedAt,
                                                  string organization = "jrolstad",
                                                  string project      = "the-project")
        {
            var key = GetProjectKey(organization, project);

            var release = root.Context.Releases[key]
                          .FirstOrDefault(r => r.name == releaseName);

            if (release == null)
            {
                throw new ArgumentOutOfRangeException(nameof(name), $"Unable to find release {releaseName}");
            }

            release.environments.Add(new ReleaseEnvironment
            {
                id          = Guid.NewGuid().ToString(),
                name        = name,
                status      = status,
                deploySteps = new List <DeployAttempt>
                {
                    new DeployAttempt
                    {
                        id       = Guid.NewGuid().ToString(),
                        queuedOn = deployedAt,
                        status   = status
                    }
                }
            });
        }
        public static void WithCommit(this TestCompositionRoot root,
                                      string repositoryName,
                                      string authorName,
                                      string authorEmail  = null,
                                      DateTime?commitDate = null,
                                      int deletions       = 0,
                                      int edits           = 0,
                                      int additions       = 0,
                                      string organization = "jrolstad",
                                      string project      = "the-project")
        {
            var item = new GitCommitRef
            {
                author = new GitUserDate
                {
                    date  = commitDate ?? DateTime.Now.AddDays(-7),
                    email = authorEmail ?? Base64Encode(authorName),
                    name  = authorName
                },
                changeCounts = new ChangeCountDictionary
                {
                    Add    = additions,
                    Edit   = edits,
                    Delete = deletions
                },
                commitId     = Guid.NewGuid().ToString(),
                RepositoryId = Base64Encode(repositoryName)
            };


            WithItem(organization, project, root.Context.Commits, item);
        }
        public static HttpRequest DeleteRequest(this TestCompositionRoot root)
        {
            var request = new DefaultHttpRequest(new DefaultHttpContext())
            {
                Method = "DELETE"
            };

            return(request);
        }
        public static HttpRequest GetRequest(this TestCompositionRoot root)
        {
            var request = new DefaultHttpRequest(new DefaultHttpContext())
            {
                Method = "GET"
            };

            return(request);
        }
        public static TestCompositionRoot TestRoot(this ScenarioContext context)
        {
            if (!context.ContainsKey("TestCompositionRoot"))
            {
                context.Set(TestCompositionRoot.Create(), "TestCompositionRoot");
            }

            return(context.Get <TestCompositionRoot>("TestCompositionRoot"));
        }
Beispiel #8
0
        public static HttpRequest WithPostRequest(this TestCompositionRoot root, Stream body)
        {
            body.Position = 0;
            var request = new DefaultHttpRequest(new DefaultHttpContext())
            {
                Body = body
            };


            return(request);
        }
        private void AssertRequestIsLogged(TestCompositionRoot root)
        {
            var requestMessages = root
                                  .Context
                                  .LogMessages
                                  .Select(m => m.Data)
                                  .Cast <Dictionary <string, object> >()
                                  .Count(d => d["action"] == "alexa-request");

            Assert.Equal(1, requestMessages);
        }
        public static HttpRequest PutRequest <T>(this TestCompositionRoot root, T body)
        {
            var request = new DefaultHttpRequest(new DefaultHttpContext())
            {
                Method = "PUT"
            };
            var bodyAsJson = JsonConvert.SerializeObject(body);

            request.Body = bodyAsJson.ToStream();

            return(request);
        }
        public static void WithCategory(this TestCompositionRoot root,
                                        string name)
        {
            var context  = root.Get <RecipeBookDbContext>();
            var category = new entityframework.Models.Category
            {
                Id   = Guid.NewGuid().ToString(),
                Name = name
            };

            context.Categories.Add(category);
            context.SaveChanges();
        }
Beispiel #12
0
        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 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 static void WithProject(this TestCompositionRoot root,
                                string name,
                                string id           = null,
                                string organization = "default")
 {
     if (!root.Context.Projects.ContainsKey(organization))
     {
         root.Context.Projects.Add(organization, new List <Project>());
     }
     root.Context.Projects[organization].Add(new Project
     {
         name = name,
         id   = id ?? Guid.NewGuid().ToString()
     });
 }
Beispiel #15
0
        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);
        }
Beispiel #16
0
        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 static void WithRepository(this TestCompositionRoot root,
                                          string name,
                                          string url          = "https://dev.azure.com/repo/{0}",
                                          long size           = 1,
                                          string organization = "jrolstad",
                                          string project      = "the-project")
        {
            var item = new GitRepository
            {
                name   = name,
                id     = Base64Encode(name),
                weburl = string.Format(url, name),
                size   = size
            };

            WithItem(organization, project, root.Context.Repositories, item);
        }
Beispiel #18
0
        public async Task SearchProjects_ValidOrganization_GetsProjects()
        {
            // Given
            var root = TestCompositionRoot.CreateIntegration();

            var viewModel = root.Get <WorkSummaryViewModel>();

            viewModel.Organization = "jrolstad";

            // When
            await viewModel.SearchProjects();

            // Then
            Assert.Null(viewModel.Error);
            Assert.NotEmpty(viewModel.Projects);
            Assert.Equal(viewModel.Projects.First(), viewModel.Project);
        }
Beispiel #19
0
        public static void WithAuthenticatedUser(this TestCompositionRoot root, string name, Dictionary <string, string> additionalClaims = null)
        {
            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.Name, name)
            };

            if (additionalClaims != null)
            {
                var additionalClaimsResolved = additionalClaims.Select(c => new Claim(c.Key, c.Value));
                claims.AddRange(additionalClaimsResolved);
            }

            var claimsIdentity = new ClaimsIdentity(claims, "some-authentication-mechanism");

            root.Context.CurrentPrincipal = new ClaimsPrincipal(claimsIdentity);
        }
        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 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 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 static void WithBranch(this TestCompositionRoot root,
                                      string repositoryName,
                                      string name,
                                      int commitsAhead    = 0,
                                      int commitsBehind   = 0,
                                      string organization = "jrolstad",
                                      string project      = "the-project")
        {
            var item = new GitBranchStat
            {
                aheadCount   = commitsAhead,
                behindCount  = commitsBehind,
                name         = name,
                RepositoryId = Base64Encode(repositoryName)
            };

            WithItem(organization, project, root.Context.BranchStats, item);
        }
Beispiel #24
0
        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);
        }
Beispiel #25
0
        public async Task Search_ValidOrganizationAndProject_GetsTeams()
        {
            // Given
            var root = TestCompositionRoot.CreateIntegration();

            var viewModel = root.Get <WorkSummaryViewModel>();

            viewModel.Organization = "microsoftit";
            viewModel.Project      = "oneitvso";
            viewModel.TeamsFilter  = "all treasury";
            viewModel.StartDate    = new DateTime(2020, 1, 1);

            // When
            await viewModel.Search();

            // Then
            Assert.Null(viewModel.Error);
            Assert.NotEmpty(viewModel.Results);
        }
Beispiel #26
0
        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 static void WithRelease(this TestCompositionRoot root,
                                       string name,
                                       string releaseDefinitionName,
                                       string url          = "https://dev.azure.com/release/{0}",
                                       string id           = null,
                                       string organization = "jrolstad",
                                       string project      = "the-project")
        {
            var item = new Release
            {
                name = name,
                id   = id ?? Base64Encode(name),
                ReleaseDefinitionId = Base64Encode(releaseDefinitionName),
                _links       = WithLinks(string.Format(url, name)),
                environments = new List <ReleaseEnvironment>()
            };

            WithItem(organization, project, root.Context.Releases, item);
        }
Beispiel #28
0
        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_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));
        }
Beispiel #30
0
        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());
        }