Skip to content

Instantly share code, notes, and snippets.

@demofan
Last active October 20, 2015 09:56
Show Gist options
  • Save demofan/8280a9b4a9be3152b051 to your computer and use it in GitHub Desktop.
Save demofan/8280a9b4a9be3152b051 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using NSubstitute.Exceptions;
namespace MVP2016
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod_MVP現有類別不在指定類別內並且不是十月份MVP可以自動延長一年()
{
//這比較能表達我想講的
IMvp mvp = Substitute.For<IMvp>();
mvp.GetInfo("demo").Returns(new MvpInfo
{
WinnerMonth = 4,
Category = "ASP.NET/IIS"
});
mvp.CheckAutoRenew(4, "ASP.NET/IIS").Returns(true);
var target = mvp.GetInfo("demo");
bool isAutoRenew = mvp.CheckAutoRenew(target.WinnerMonth, target.Category);
Assert.IsTrue(isAutoRenew);
}
[TestMethod]
public void TestMethod_MVP現有類別不在指定類別內並且不是十月份MVP可以自動延長一年2()
{
//這才像測試...
IMvp mvp = new mvp();
var target = mvp.GetInfo("demo");
bool isAutoRenew = mvp.CheckAutoRenew(target.WinnerMonth, target.Category);
Assert.IsTrue(isAutoRenew);
}
}
public class MvpInfo
{
public int WinnerMonth { get; set; }
public string Category { get; set; }
}
public interface IMvp
{
MvpInfo GetInfo(string demo);
bool CheckAutoRenew(int winnerMonth, string category);
}
public class mvp : IMvp
{
private List<string> CantAutoRenewCategory = new List<string>()
{
"Consumer Security",
"Windows Consumer Apps",
"Windows Experience",
"Windows Phone",
"Surface",
"ID@Xbox",
"Xbox",
"Bing Ads",
"Access",
"Excel",
"Macintosh",
"Office System",
"OneNote",
"Outlook",
"PowerPoint",
"Publisher",
"Visio",
"Word"
};
public MvpInfo GetInfo(string name)
{
if (name=="demo")
{
return new MvpInfo() {WinnerMonth = 4,Category = "ASP.NET/IIS"};
}
return null;
}
public bool CheckAutoRenew(int winnerMonth, string category)
{
if (winnerMonth == 10 || CantAutoRenewCategory.Contains(category))
{
return false;
}
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment