-
Notifications
You must be signed in to change notification settings - Fork 34
Implementing GetProject() with lambda calls #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WiseLordship
wants to merge
3
commits into
QualiSystems:master
Choose a base branch
from
WiseLordship:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using FakeItEasy; | ||
| using FluentAssertions; | ||
| using FluentTc.Domain; | ||
| using FluentTc.Engine; | ||
| using FluentTc.Exceptions; | ||
| using FluentTc.Locators; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace FluentTc.Tests | ||
| { | ||
| [TestFixture] | ||
| public class ProjectRetrievalTests | ||
| { | ||
| [TestCase("FluentTC")] | ||
| [TestCase("Test 1")] | ||
| [TestCase("Test!@#$%^&*()")] | ||
| public void GetProject_ById(string projectId) | ||
| { | ||
| // Arrange | ||
| var teamCityCaller = A.Fake<ITeamCityCaller>(); | ||
| A.CallTo( | ||
| () => | ||
| teamCityCaller.GetFormat<ProjectWrapper>("/app/rest/projects/{0}", | ||
| string.Format("id:{0}", projectId))) | ||
| .Returns(new ProjectWrapper | ||
| { | ||
| Project = new List<Project> { new Project { Id = projectId, Name = "Test 1" } }, | ||
| Count = "1" | ||
| }); | ||
|
|
||
| var projectsRetriever = new ProjectsRetriever(new BuildProjectHavingBuilderFactory(), teamCityCaller); | ||
|
|
||
| // Act | ||
| var result = projectsRetriever.GetProject(project => project.Id(projectId)); | ||
|
|
||
| // Assert | ||
| result.Should().NotBeNull(); | ||
| result.Name.Should().Be("Test 1"); | ||
| result.Id.Should().Be(projectId); | ||
| } | ||
|
|
||
| [TestCase("1234")] | ||
| [TestCase("ABcd")] | ||
| [TestCase("129@$$jd")] | ||
| public void GetProject_ByName(string projectName) | ||
| { | ||
| // Arrange | ||
| var teamCityCaller = A.Fake<ITeamCityCaller>(); | ||
| A.CallTo( | ||
| () => | ||
| teamCityCaller.GetFormat<ProjectWrapper>("/app/rest/projects/{0}", | ||
| string.Format("name:{0}", projectName))) | ||
| .Returns(new ProjectWrapper | ||
| { | ||
| Project = new List<Project> { new Project { Id = "Project1", Name = projectName } }, | ||
| Count = "1" | ||
| }); | ||
|
|
||
| var projectsRetriever = new ProjectsRetriever(new BuildProjectHavingBuilderFactory(), teamCityCaller); | ||
|
|
||
| // Act | ||
| var result = projectsRetriever.GetProject(project => project.Name(projectName)); | ||
|
|
||
| // Assert | ||
| result.Should().NotBeNull(); | ||
| result.Name.Should().Be(projectName); | ||
| result.Id.Should().Be("Project1"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void GetProject_MultipleProjects_MoreThanOneProjectFoundExceptionThrown() | ||
| { | ||
| // Arrange | ||
| var teamCityCaller = A.Fake<ITeamCityCaller>(); | ||
| A.CallTo( | ||
| () => | ||
| teamCityCaller.GetFormat<ProjectWrapper>("/app/rest/projects/{0}", "name:exception")) | ||
| .Returns(new ProjectWrapper { Project = new List<Project>{new Project(), new Project()}, Count = "2" }); | ||
|
|
||
| var projectsRetriever = new ProjectsRetriever(new BuildProjectHavingBuilderFactory(), teamCityCaller); | ||
|
|
||
| // Act | ||
| Action action = () => projectsRetriever.GetProject(project => project.Name("exception")); | ||
|
|
||
| // Assert | ||
| action.ShouldThrow<MoreThanOneProjectFoundException>(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void GetProject_NoProjects_ProjectNotFoundException() | ||
| { | ||
| // Arrange | ||
| var teamCityCaller = A.Fake<ITeamCityCaller>(); | ||
| A.CallTo( | ||
| () => | ||
| teamCityCaller.GetFormat<ProjectWrapper>( | ||
| "/app/rest/projects?locator={0}", | ||
| A<object[]>.That.IsSameSequenceAs(new[] { "enabled:False" }))) | ||
| .Returns(new ProjectWrapper { Project = new List<Project>(), Count = "0" }); | ||
|
|
||
| var projectsRetriever = new ProjectsRetriever(new BuildProjectHavingBuilderFactory(), teamCityCaller); | ||
|
|
||
| // Act | ||
| Action action = () => projectsRetriever.GetProject(project => project.Name("exception")); | ||
|
|
||
| // Assert | ||
| action.ShouldThrow<ProjectNotFoundException>(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using System; | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace FluentTc.Exceptions | ||
| { | ||
| [Serializable] | ||
| public class MoreThanOneProjectFoundException : Exception | ||
| { | ||
| public MoreThanOneProjectFoundException() | ||
| { | ||
| } | ||
|
|
||
| public MoreThanOneProjectFoundException(string message) : base(message) | ||
| { | ||
| } | ||
|
|
||
| public MoreThanOneProjectFoundException(string message, Exception innerException) : base(message, innerException) | ||
| { | ||
| } | ||
|
|
||
| protected MoreThanOneProjectFoundException(SerializationInfo info, StreamingContext context) : base(info, context) | ||
| { | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using System; | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace FluentTc.Exceptions | ||
| { | ||
| [Serializable] | ||
| public class ProjectNotFoundException : Exception | ||
| { | ||
| public ProjectNotFoundException() | ||
| { | ||
| } | ||
|
|
||
| public ProjectNotFoundException(string message) : base(message) | ||
| { | ||
| } | ||
|
|
||
| public ProjectNotFoundException(string message, Exception innerException) : base(message, innerException) | ||
| { | ||
| } | ||
|
|
||
| protected ProjectNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) | ||
| { | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are acceptance tests and they should reside inside
AcceptanceTestsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will move these to AcceptanceTests and will make better overall tests for the method. I started here when I was trying t make more robust tests, and did not move these out.