Compare commits

...

19 Commits

@ -45,6 +45,12 @@
<ItemGroup>
<Compile Include="Student.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="xUnitStudy\AssertEqualDemo.cs" />
<Compile Include="xUnitStudy\CollectionFixtureDemo.cs" />
<Compile Include="xUnitStudy\ClassFixtureDemo.cs" />
<Compile Include="xUnitStudy\IPerson.cs" />
<Compile Include="xUnitStudy\Person.cs" />
<Compile Include="xUnitStudy\Teacher.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace xUnitStudy.Model
{
public class AssertEqualDemo : IEqualityComparer<AssertEqualDemo>
{
public int Id { get; set; }
public string Name { get; set; }
public bool Equals(AssertEqualDemo x, AssertEqualDemo y)
{
return x.Id == y.Id;
}
public int GetHashCode(AssertEqualDemo obj)
{
return Id;
}
}
}

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace xUnitStudy.Model
{
/// <summary>
/// 测试方法共享对象实例
/// </summary>
public class ClassFixtureDemo : IDisposable
{
public int CallTimes { get; private set; }
public List<Person> Persons;
public ClassFixtureDemo()
{
Persons = new List<Person>()
{
new Person(){ Id=1, FirstName="first1",LastName="last1" },
new Person(){ Id=2, FirstName="first2",LastName="last2" },
new Person(){ Id=3, FirstName="first3",LastName="last3" },
};
}
public (bool result, Person person) AddPerson(Person person)
{
CallTimes += 1;
var exist = Persons.FirstOrDefault(p => p.Id == person.Id);
if (exist == null)
{
Persons.Add(person);
return ValueTuple.Create(true, person);
}
else
{
return ValueTuple.Create(false, person);
}
}
public (bool result, Person person) RemovePerson(Person person)
{
CallTimes += 1;
var exist = Persons.FirstOrDefault(p => p.Id == person.Id);
if (exist == null)
{
return ValueTuple.Create(false, person);
}
else
{
Persons.Remove(exist);
return ValueTuple.Create(true, exist);
}
}
public void Dispose()
{
Persons = null;
}
}
}

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace xUnitStudy.Model
{
/// <summary>
/// 测试方法共享对象实例
/// </summary>
public class CollectionFixtureDemo : IDisposable
{
public List<Person> Persons;
public CollectionFixtureDemo()
{
Persons = new List<Person>()
{
new Person(){ Id=1, FirstName="first1",LastName="last1" },
new Person(){ Id=2, FirstName="first2",LastName="last2" },
new Person(){ Id=3, FirstName="first3",LastName="last3" },
};
}
public Person GetPersonById(int personId)
{
var find = Persons.FirstOrDefault(p => p.Id == personId);
return find;
}
public void Dispose()
{
Persons = null;
}
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace xUnitStudy.Model
{
public interface IPerson
{
int Id { get; set; }
string FirstName { get; set; }
string LastName { get; set; }
string GetFullName();
}
}

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace xUnitStudy.Model
{
public class Person:IPerson,IEqualityComparer<Person>,IComparer<Person>
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string GetFullName()
{
return FirstName + "_" + LastName;
}
public bool Equals(Person x, Person y)
{
return x.Id == y.Id;
}
public int GetHashCode(Person obj)
{
return obj.Id;
}
/// <summary>
/// IComparer接口实现
/// </summary>
/// <param name="x">比较对象1</param>
/// <param name="y">比较对象2</param>
/// <returns>x小于y则返回负整数x大于y则返回正整数x等于y则返回0</returns>
public int Compare(Person x, Person y)
{
if (x.Id < y.Id)
{
return -1;
}
else if (x.Id == y.Id)
{
return 0;
}
else
{
return 1;
}
}
}
}

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace xUnitStudy.Model
{
public class Teacher:Person
{
public int Grade { get; set; }
}
}

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using xUnitStudy.Model;
using xUnitStudy.WebApi;
using xUnitStudy.WebApi.Controllers;
namespace xUnitStudy.WebApi.Test
{
public class ApiControllerTest
{
[Fact]
public void Test()
{
var id = 5;
var valueController = new ValuesController();
var result = valueController.Get(id);
Assert.Equal(id.ToString(), result);
}
}
}

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autofac;
using Autofac.Builder;
using Autofac.Core;
using Autofac.Extras;
using Autofac.Features;
using Autofac.Util;
namespace xUnitStudy.WebApi.Test.AutoFac
{
public class AutofacStudy
{
}
}

@ -1,6 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
@ -34,3 +35,6 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//xUnit 分组设置
[assembly:AssemblyTrait("程序集分组","包括程序集内测试方法")]

@ -17,15 +17,97 @@ namespace xUnitStudy.WebApi.Test
{
public class StudentBllTest:IDisposable
{
private StudentBll bll;
#region 准备
private StudentBll actualBll;
public StudentBllTest()
{
bll = new Bll.StudentBll();
//这里创建和设置需要注入的IDal。当然也可以创建和设置直接注入。
actualBll = new Bll.StudentBll();
}
#endregion
[Fact]
public void GetTuitionTest()
public void Students_Test()
{
IStudentBll actual_Bll = new StudentBll();
List<Student> studentsFromProperty = actual_Bll.Students;
List<Student> studentsFromMethod = actual_Bll.GetAll();
Assert.Equal(studentsFromMethod, studentsFromProperty);
}
[Fact]
public void GetAll_Test()
{
List<Student> students = actualBll.GetAll();
Assert.Equal(actualBll.Students, students);
}
[Fact]
public void GetStudentById_Test()
{
var studentId = 1;
Student student = actualBll.GetStudentById(studentId);
Assert.NotNull(student);
Assert.Equal(studentId, student.Id);
}
[Fact]
public void AddStudent_Test()
{
var exitsStudent = new Student() { Id=1,Name="lishi",Age=40,lever=0};
var newStudent = new Student() { Id=100,Name="wangwu",Age=30,lever=0};
var exitsResult = actualBll.AddStudent(exitsStudent);
var newResult = actualBll.AddStudent(newStudent);
Assert.False(exitsResult.result);
Assert.True(newResult.result);
Assert.Contains(newStudent, actualBll.GetAll());
}
[Fact]
public void UpdateStudent_Test()
{
var exitsStudent = new Student() { Id = 1, Name = "lishi", Age = 40, lever = 0 };
var newStudent = new Student() { Id = 100, Name = "wangwu", Age = 30, lever = 0 };
var exitsResult = actualBll.UpdateStudent(exitsStudent);
var newResult = actualBll.UpdateStudent(newStudent);
Assert.True(exitsResult.result);
Assert.Contains(exitsStudent, actualBll.GetAll());
Assert.False(newResult.result);
}
[Fact]
public void DeleteStudent_Test()
{
var exitsStudent = new Student() { Id = 1, Name = "lishi", Age = 40, lever = 0 };
var newStudent = new Student() { Id = 100, Name = "wangwu", Age = 30, lever = 0 };
var exitsResult = actualBll.DeleteStudent(exitsStudent.Id);
var newResult = actualBll.DeleteStudent(newStudent.Id);
Assert.True(exitsResult);
Assert.DoesNotContain(exitsStudent, actualBll.GetAll());
Assert.False(newResult);
}
/// <summary>
/// 获取学费
/// 属性注入IDal Mock对象
/// </summary>
[Fact]
public void GetTuition_UseMoq_Test()
{
// #准备
Mock<IStudentDal> mockStudentDal = new Mock<IStudentDal>();
mockStudentDal
.Setup(m => m.GetStudentById(2))
@ -33,18 +115,23 @@ namespace xUnitStudy.WebApi.Test
(
new Student() { Id = 2, Name = "小小张", Age = 95 }
);
//属性注入
bll.dal = mockStudentDal.Object;
var student = bll.GetStudentById(2);
var tuition = bll.GetTuition(2);
//属性注入,也可以使用构造函数注入
actualBll.dal = mockStudentDal.Object;
// #使用
var student = actualBll.GetStudentById(2);
var tuition = actualBll.GetTuition(2);
// #断言
Assert.Equal(student.Id + student.Age, tuition);
}
#region 清理
public void Dispose()
{
}
#endregion
}
}

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions;
using Xunit.Sdk;
namespace xUnitStudy.WebApi.Test
{
/// <summary>
/// 输出窗口的测试选项,显示测试相关信息
/// </summary>
public class TestCaseOrderTest: ITestCaseOrderer
{
private readonly IMessageSink diagnosticMessageSink;
public TestCaseOrderTest(IMessageSink diagnosticMessageSink)
{
this.diagnosticMessageSink = diagnosticMessageSink;
}
public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases) where TTestCase : ITestCase
{
var result = testCases.ToList(); // Run them in discovery order
var message = new DiagnosticMessage("Ordered {0} test cases", result.Count);
diagnosticMessageSink.OnMessage(message);
return result;
}
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions;
using Xunit.Sdk;
using xUnitStudy.Model;
namespace xUnitStudy.WebApi.Test
{
/// <summary>
/// 设置全局共享
/// </summary>
[CollectionDefinition("Demo Collection")]
public class CollectionFixtureSetup:ICollectionFixture<CollectionFixtureDemo>
{
//这个类没有代码,而不需要创建。
//其目的是简单地设置测试集共享数据
//只要设置[CollectionDefinition("Demo Collection")]特性
//并实现IClassFixture<T>接口
}
}

@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions;
using Xunit.Sdk;
using xUnitStudy.Model;
namespace xUnitStudy.WebApi.Test
{
/// <summary>
/// 测试类级别的共享(类内所有测试用例,共享一个类的实例)
/// </summary>
public class UseIClassFixtureTest:IClassFixture<ClassFixtureDemo>, IDisposable
{
/* IClassFixture使:
*
* 01Fixture,IDisposable
* 02 IClassFixture<T>T Fixture
* 03Fixture使Context.
* xUnit.Net
*
*
*
*
*
* xUnit Fixture
*
* b --> Fixture --> --> 1 --> Dispose() --> -->
*
* a --> Fixture --> --> 2 --> Dispose() --> -->
*
* x --> Fixture --> --> 2 --> Dispose() --> -->
*
* m --> Fixture--> --> 2 --> Dispose() --> -->
* ........
*
*
*
*
*
*
* 使
*
* 使
*/
ClassFixtureDemo fixtureDemo;
public UseIClassFixtureTest(ClassFixtureDemo fixture)
{
this.fixtureDemo = fixture;
}
[Fact]
public void NotNull_Test()
{
Assert.NotNull(fixtureDemo);
}
[Fact]
public void GetPersons_Test()
{
var persons = fixtureDemo.Persons;
//因为共享所以数量不一定是初始值3
//Assert.Equal(3,fixtureDemo.Persons.Count);
}
[Fact]
public void AddPerson_Test()
{
var callTimes_start = fixtureDemo.CallTimes;
var person1 = new Person() { Id=1,FirstName="first",LastName="last"};
var person2 = new Person() {Id=200};
//因为共享在不能保证单元测试的执行先后顺充时或者并行执行单元测试时可能id=1的项已被删除也可能没被删除
//所以result1可能失败也可能成功
var result1 = fixtureDemo.AddPerson(person1);
var result2 = fixtureDemo.AddPerson(person2);
//Assert.False(result1.result); 执行成功与否,取决于添加和删除单元测试的执行顺序。因为执行顺序不能确定,所以结果不定。
Assert.True(result2.result);
Assert.Equal(4, fixtureDemo.Persons.Count);
Assert.Contains(person2, fixtureDemo.Persons);
var callTimes_end = fixtureDemo.CallTimes;
Assert.Equal(2, callTimes_end - callTimes_start);
}
[Fact]
public void RemovePerson_Test()
{
var person1 = new Person() { Id = 1, FirstName = "first", LastName = "last" };
var person2 = new Person() { Id = 100 };
var result1 = fixtureDemo.RemovePerson(person1);
var result2 = fixtureDemo.RemovePerson(person2);
Assert.True(result1.result);
Assert.False(result2.result);
Assert.DoesNotContain(person1, fixtureDemo.Persons);
Assert.DoesNotContain(person2, fixtureDemo.Persons);
}
public void Dispose()
{
}
}
}

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions;
using Xunit.Sdk;
using xUnitStudy.Model;
namespace xUnitStudy.WebApi.Test
{
/// <summary>
/// Collection级别的Fixture
/// 测试程序集中所有测试类可以共享
/// </summary>
[Collection("Demo Collection")]
public class UseICollectionFixtureTest
{
/* ICollectionFixture使
*
* 01Fixture,IDisposable
* 02Collection, [CollectionDefinition], .
* 03CollectionICollectionFixture<T>T Fixture.
* 04[Collection],使[CollectionDefinition]
* 05使xUnit.Net
*
*
*
*
*
*
* xUnit ICollectionFixture
*
* x
*
* xUnit Fixture
*
* b --> ICollectionFixture --> ClassFixture --> --> 1 --> Dispose() --> -->
*
* a --> ICollectionFixture --> ClassFixture --> --> 2 --> Dispose() --> -->
*
* x --> ICollectionFixture --> ClassFixture --> --> 2 --> Dispose() --> -->
*
* m --> ICollectionFixture --> ClassFixture --> --> 2 --> Dispose() --> -->
* ........
*
*
*
* y m n a ......
*
* ..........
*
*
*
* ICollectionFixture
*
*
*
*
*
* (ICollectionFixtureClassFixture)使
*
* 使
*/
CollectionFixtureDemo fixtureDemo;
public UseICollectionFixtureTest(CollectionFixtureDemo fixture)
{
fixtureDemo = fixture;
}
[Fact]
public void Test()
{
var persons = fixtureDemo.GetPersonById(1);
Assert.True(persons.Id == 1, "使用全局共享对象");
}
}
}

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions;
using Xunit.Sdk;
using xUnitStudy.Model;
namespace xUnitStudy.WebApi.Test
{
/// <summary>
/// 测试用例级别的共享
/// </summary>
public class UseFixtureTest:IDisposable
{
/*
Test case
1IDisposableDispose()
b --> --> 1 --> Dispose() --> -->
a --> --> 2 --> Dispose() --> -->
x --> --> 2 --> Dispose() --> -->
m --> --> 2 --> Dispose() --> -->
........
xUnit
*/
object sharedData;
public UseFixtureTest()
{
//测试用例执行前做准备
sharedData = "sharedate";
}
[Fact]
public void Case2_Test()
{
Assert.Equal("sharedate", sharedData.ToString());
}
[Fact]
public void Case1_Test()
{
Assert.Equal("sharedate", sharedData.ToString());
}
public void Dispose()
{
//测试用例执行后做清理
sharedData = null;
}
}
}

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions;
using Xunit.Sdk;
using xUnitStudy.Model;
namespace xUnitStudy.WebApi.Test.UseFixture
{
/// <summary>
/// 同时使用多种共享
/// </summary>
[Collection("Demo Collection")]
public class UseFullFixtures : IDisposable, IClassFixture<ClassFixtureDemo>
{
CollectionFixtureDemo collectionFixture;
ClassFixtureDemo classFixture;
public UseFullFixtures(CollectionFixtureDemo collectionDemo, ClassFixtureDemo fixtureDemo)
{
classFixture = fixtureDemo;
collectionFixture = collectionDemo;
}
[Fact]
public void Test()
{
Assert.NotNull(classFixture);
var person = collectionFixture.GetPersonById(2);
Assert.Equal(2, person.Id);
}
public void Dispose()
{
//每个测试用例的清理
}
}
}

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
namespace xUnitStudy.WebApi.Test
{
public class UseOutputTest
{
private readonly ITestOutputHelper output;
public UseOutputTest(ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void Test()
{
Assert.True(true, "输出测试");
output.WriteLine("我是输出测试信息哦。");
}
}
}

@ -5,15 +5,130 @@ using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions;
using Xunit.Sdk;
namespace xUnitStudy.WebApi.Test
{
public class UseXUnitTest
/// <summary>
/// 使用 xUnit
/// 测试类不需要加任何特性
/// NUnit需要加TestFixture特性MSTest需要加TestClass特性
/// </summary>
[Trait(name:"测试类分组",value:"包括类内所有测试方法")]
public class UseXUnitTest:IDisposable
{
/// <summary>
/// 每次测试前的准备
/// 构造函数 替代 SetUp或TestInitialize进行初始化
/// </summary>
public UseXUnitTest()
{
}
/// <summary>
/// 每次测试后的清理
/// 实现IDisposable接口替代TearDown或TestCleanup 进行清理释放操作
/// </summary>
public void Dispose()
{
}
/// <summary>
/// Fact特性标识测试方法
/// </summary>
[Fact]
public void Test()
public void Use_Fact_Test()
{
//永久通过测试断言的写法
Assert.True(true,"Fact特性,表示测试方法");
}
[Fact(DisplayName = "定制测试方法名称")]
public void Use_Fact_DisplayName_Test()
{
Assert.Equal(1, 1);
Assert.True(true,"使用Fact特性的DisplayName属性,表示:定制的测试方法名称");
}
[Fact(Skip = "暂时忽略测试")]
public void Use_Fact_Skip_Test()
{
Assert.True(true,"使用Fact特性的Skip属性,表示:暂时忽略测试");
}
/// <summary>
/// 使用Fact特性的Timeout参数
/// 设置:测试方法超时时间(豪秒)
/// </summary>
[Fact(Timeout =1000)]
public void Use_Fact_Timeout_Test()
{
Assert.True(true,"使用Fact特性的Timeout属性,设置:测试方法超时时间(豪秒)");
}
/// <summary>
/// 分组测试,可以按分组显示测试结果
/// Trait可用于程序集(AssemblyInfo.cs文件中)、测试类和测试方法三个层次
/// 一个测试方法同时属于多外组
/// </summary>
[Fact]
[Trait(name:"测试方法分组",value:"红队")]
[Trait(name:"测试方法分组",value:"蓝队")]
public void Use_Trait_Test()
{
Assert.True(true,"使用Trait特性,设置:测试分组,测试结果可以按组显示");
}
/// <summary>
/// 测试方法分组:红队
/// </summary>
[Fact]
[Trait(name: "测试方法分组", value: "红队")]
public void Use_Trait_Red_Test()
{
Assert.True(true, "使用Trait特性,设置:测试分组,测试结果可以按组显示");
}
/// <summary>
/// 测试方法分组:蓝队
/// </summary>
[Fact]
[Trait(name: "测试方法分组", value: "蓝队")]
public void Use_Trait_Blue_Test()
{
Assert.True(true, "使用Trait特性,设置:测试分组,测试结果可以按组显示");
}
[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
public void Use_Theory_Test(int number)
{
var userPara = number;
Assert.True(true,"使用Theory特性和InlineData特性传递不同参数多次执行测试");
}
/// <summary>
/// 断言不抛出异常
/// </summary>
[Fact]
public void Assert_NoThrow_Test()
{
Action noThrowAction =() =>
{
//业务代码
Task.Delay(10);
//throw new Exception("测试异常");
};
var exception = Record.Exception(noThrowAction);
Assert.Null(exception);
}
}
}

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="xunit.diagnosticMessages" value="true"/>
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
@ -22,6 +25,10 @@
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.9.0.0" newVersion="4.9.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="4.0.1" targetFramework="net452" />
<package id="Autofac.Extras.Moq" version="4.2.0" targetFramework="net452" />
<package id="Castle.Core" version="4.3.1" targetFramework="net452" />
<package id="Moq" version="4.9.0" targetFramework="net452" />
<package id="System.ComponentModel.Primitives" version="4.1.0" targetFramework="net452" />
<package id="System.ComponentModel.TypeConverter" version="4.1.0" targetFramework="net452" />
<package id="System.Net.Http" version="4.3.3" targetFramework="net452" />
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net452" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net452" />

@ -34,6 +34,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=4.0.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.4.0.1\lib\net45\Autofac.dll</HintPath>
</Reference>
<Reference Include="Autofac.Extras.Moq, Version=4.2.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.Extras.Moq.4.2.0\lib\net45\Autofac.Extras.Moq.dll</HintPath>
</Reference>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
</Reference>
@ -41,6 +47,12 @@
<HintPath>..\packages\Moq.4.9.0\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Primitives, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.ComponentModel.Primitives.4.1.0\lib\net45\System.ComponentModel.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.TypeConverter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.ComponentModel.TypeConverter.4.1.0\lib\net45\System.ComponentModel.TypeConverter.dll</HintPath>
</Reference>
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
@ -49,6 +61,7 @@
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -69,8 +82,18 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ApiControllerTest.cs" />
<Compile Include="AutoFac\AutofacStudy.cs" />
<Compile Include="TestCaseOrderTest.cs" />
<Compile Include="UseFixture\CollectionFixtureSetup.cs" />
<Compile Include="StudentBll\StudentBllTest.cs" />
<Compile Include="StudentDal\StudentDalTest.cs" />
<Compile Include="UseAssertTest.cs" />
<Compile Include="UseFixture\UseFixtureTest.cs" />
<Compile Include="UseFixture\UseClassFixtureTest.cs" />
<Compile Include="UseFixture\UseCollectionFixtureTest.cs" />
<Compile Include="UseFixture\UseFullFixtures.cs" />
<Compile Include="UseOutputTest.cs" />
<Compile Include="UseXUnitTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@ -107,7 +130,9 @@
<Name>xUnitStudy.WebApi</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="ApiController\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>

@ -18,15 +18,23 @@ namespace xUnitStudy.WebApi.Controllers
return new string[] { "value1", "value2" };
}
// GET api/values/5
[System.Web.Http.Authorize]
public string Get(int id)
{
return id.ToString();
}
// POST api/values
public void Post([FromBody]string value)
public IHttpActionResult Post([FromBody]string value)
{
var cc = new System.Web.Http.Results.CreatedAtRouteNegotiatedContentResult<string>
(
"",
new Dictionary<string, object> { { "id",2} },
"",
this
);
return cc;
}
// PUT api/values/5

Loading…
Cancel
Save