Last active
January 23, 2021 14:18
-
-
Save yuriylsh/5c099d81c33111b05195bf6ad60e683f to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using LanguageExt; | |
using LanguageExt.UnitTesting; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
namespace Issue9 | |
{ | |
[TestClass] | |
public class LanguageExtUnitTestingIssue9 | |
{ | |
private static readonly DateTime _date = new DateTime(2020, 6, 15); | |
[TestMethod] | |
public void Investor_CurrentTerm_OneForTheCurrentDate() { | |
Investor investor = new() { | |
Terms = new List<Term> { | |
new() { Start = new(2020, 1, 1), End = new(2020, 12, 31) } | |
} | |
}; | |
Option<Term> term = investor.CurrentTerm(_date); | |
term.ShouldBeSome(t => Assert.AreEqual(new DateTime(2020, 1, 1), t.Start)); | |
} | |
} | |
public record Investor { | |
public IReadOnlyList<Term> Terms { get; init; } | |
public Option<Term> CurrentTerm(DateTime currentDate) => | |
Terms.FirstOrDefault(x => x.Start <= currentDate && x.End > currentDate) is {} found ? found : Option<Term>.None; | |
} | |
public record Term { | |
public DateTime Start { get; init; } | |
public DateTime End { get; init; } | |
} | |
} |
This file contains 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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFramework>net5.0</TargetFramework> | |
<LangVersion>latest</LangVersion> | |
<IsPackable>false</IsPackable> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="LanguageExt.Core" Version="3.4.15" /> | |
<PackageReference Include="LanguageExt.UnitTesting" Version="3.3.5" /> | |
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" /> | |
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" /> | |
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment