Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CourseApp.Tests/CourseApp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.15.2" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />
Expand Down
43 changes: 41 additions & 2 deletions CourseApp.Tests/DemoTest.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,53 @@
using System;
using Xunit;
using Moq;

namespace CourseApp.Tests
{
public class DemoTest
{
[Theory]
[InlineData(5, 5, 10)]
[InlineData(-5, -5, -10)]
[InlineData(-5, 5, 0)]
[InlineData(0, 0, 0)]
public void TestCalc(int x, int y, int exp)
{
Numer a = new Numer();
a.Value = x;
Numer b = new Numer();
b.Value = y;
Assert.Equal(exp, Program.Calc(a, b));
}

[Fact]
public void TestForOneNull()
{
Numer a = new Numer();
Numer b = new Numer();
a.Value = null;
b.Value = 1;
Assert.Throws<System.NullReferenceException>(() => Program.Calc(a, b));
}

[Fact]
public void TestForNull()
{
Numer a = new Numer();
Numer b = new Numer();
a.Value = null;
b.Value = null;
Assert.Throws<System.NullReferenceException>(() => Program.Calc(a, b));
}

[Fact]
public void Test1()
public void TestFuntionRun()
{
Assert.True(true);
var mock = new Mock<ClassB>();
mock.Setup(b => b.B(It.IsAny<int>()));
var classA = new ClassA(mock.Object);
var exp = classA.B();
mock.Verify(b => b.B(It.IsAny<int>()), Times.Once());
}
}
}
20 changes: 20 additions & 0 deletions CourseApp/ClassA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace CourseApp
{
public class ClassA
{
private int a = 0;
private ClassB b = new ClassB();

public ClassA(ClassB b)
{
this.b = b;
}

public int B()
{
return this.b.B(a);
}
}
}
13 changes: 13 additions & 0 deletions CourseApp/ClassB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace CourseApp
{
public class ClassB
{
public virtual int B(int a)
{
a++;
return a;
}
}
}
9 changes: 9 additions & 0 deletions CourseApp/Numer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace CourseApp
{
public class Numer
{
public object Value { get; set; }
}
}
27 changes: 26 additions & 1 deletion CourseApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,34 @@ namespace CourseApp
{
public class Program
{
public static int Calc(Numer a, Numer b)
{
if ((a.Value == null) || (b.Value == null))
{
throw new NullReferenceException("a or b is null");
}
else
{
int c = (int)a.Value + (int)b.Value;
return c;
}
}

public static void Task2()
{
ClassB b = new ClassB();
ClassA a = new ClassA(b);
Console.WriteLine(a.B());
}

public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Numer a = new Numer();
Numer b = new Numer();
a.Value = 5;
b.Value = 5;
Console.WriteLine(Program.Calc(a, b));
Task2();
Console.ReadLine();
}
}
Expand Down