Skip to content

Instantly share code, notes, and snippets.

@Polaroid15
Created January 10, 2021 15:39
Show Gist options
  • Save Polaroid15/9ba2d6a2b78e7a97ce4cc313152ed08d to your computer and use it in GitHub Desktop.
Save Polaroid15/9ba2d6a2b78e7a97ce4cc313152ed08d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using bgTeam.DataAccess;
using ISales.Router.Story.Routing;
using Moq;
using Xunit;
namespace ISales.Router.UnitTests.StoryTests
{
public class FindRoutesStoryTests
{
private readonly Mock<IRepository> _repository;
public FindRoutesStoryTests()
{
_repository = new Mock<IRepository>();
}
public static IEnumerable<object[]> GetSuccessFindRoutesStoryContext()
{
yield return new object[]
{
new FindRoutesStoryContext() { FromPointId = 1, PlanDateStart = DateTime.Now, ToPointId = 2 },
};
yield return new object[]
{
new FindRoutesStoryContext() { FromPointId = 2, PlanDateStart = DateTime.Now.AddDays(5), ToPointId = 3 },
};
}
public static IEnumerable<object[]> GetFailedFindRoutesStoryContext()
{
yield return new object[]
{
new FindRoutesStoryContext() { FromPointId = 33, PlanDateStart = null, ToPointId = 1 },
};
yield return new object[]
{
new FindRoutesStoryContext() { FromPointId = 22, PlanDateStart = DateTime.Now, ToPointId = 51 },
};
yield return new object[]
{
new FindRoutesStoryContext() { FromPointId = 22, PlanDateStart = DateTime.Now},
};
yield return new object[]
{
new FindRoutesStoryContext() { PlanDateStart = DateTime.Now, ToPointId = 51 },
};
}
[Theory]
[MemberData(nameof(GetSuccessFindRoutesStoryContext))]
public void FindRoute_Exist(FindRoutesStoryContext routeContext)
{
var story = new FindRoutesStory(_repository.Object);
var result = story.Execute(routeContext);
Assert.NotEmpty(result);
}
[Theory]
[MemberData(nameof(GetFailedFindRoutesStoryContext))]
public void FindRoute_NotExist(FindRoutesStoryContext routeContext)
{
var story = new FindRoutesStory(_repository.Object);
var result = story.Execute(routeContext);
Assert.Empty(result);
}
[Fact]
public void FindRoute_NotExistStartDate()
{
var routeContext = new FindRoutesStoryContext()
{
FromPointId = 1, ToPointId = 2,
};
var story = new FindRoutesStory(_repository.Object);
var resultRoutes = story.Execute(routeContext);
var route = resultRoutes.First();
var expectedDate = DateTime.Now.AddDays(1).Date;
Assert.Equal(expectedDate, route.StartTime.Date);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment