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
17 changes: 15 additions & 2 deletions CourseApp.Tests/DemoTest.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
using System;
using Xunit;
using Moq;

namespace CourseApp.Tests
{
public class DemoTest
{
[Fact]
public void Test1()
public void NullException()
{
Assert.True(true);
Car car1 = new Car();
var result = Assert.Throws<ArgumentNullException>(() => car1.Sum(null)).Message;
Assert.Equal("Value cannot be null.\nParameter name: One or more values is null.", result);
}

[Fact]
public void TestFuntionRun()
{
var mockAnotherService = new Mock<TouchPad>();
mockAnotherService.Setup(e => e.Touch(It.IsAny<int>()));
var motherBoard1 = new MotherBoard(mockAnotherService.Object);
var result = motherBoard1.Touch();
mockAnotherService.Verify(e => e.Touch(It.IsAny<int>()), Times.Once());
}
}
}
20 changes: 20 additions & 0 deletions CourseApp/Car.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace CourseApp
{
public class Car
{
private object firstSpeed = 12.9;

public double Sum(object secondSpeed)
{
if ((firstSpeed == null) || (secondSpeed == null))
{
throw new ArgumentNullException("One or more values is null.");
}

double sum = (double)firstSpeed + (double)secondSpeed;
return sum;
}
}
}
20 changes: 20 additions & 0 deletions CourseApp/MotherBoard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace CourseApp
{
public class MotherBoard
{
private int times = 0;
private TouchPad touchPad1 = new TouchPad();

public MotherBoard(TouchPad touchPad2)
{
this.touchPad1 = touchPad2;
}

public int Touch()
{
return this.touchPad1.Touch(times);
}
}
}
19 changes: 17 additions & 2 deletions CourseApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@ namespace CourseApp
{
public class Program
{
public static void Main(string[] args)
public static void TaskN1()
{
Console.WriteLine("Hello World!");
Car car1 = new Car();
object speed = 12.3;
Console.WriteLine(car1.Sum(speed));
}

public static void TaskN2()
{
TouchPad touchPad1 = new TouchPad();
MotherBoard motherBoard1 = new MotherBoard(touchPad1);
Console.WriteLine(motherBoard1.Touch());
}

public static void Main()
{
TaskN1();
TaskN2();
Console.ReadLine();
}
}
Expand Down
13 changes: 13 additions & 0 deletions CourseApp/TouchPad.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace CourseApp
{
public class TouchPad
{
public virtual int Touch(int times)
{
times++;
return times;
}
}
}