diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 8fb7e4a..e253b4b 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -9,6 +9,7 @@ + diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index fdc46f5..ec1bd63 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -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(() => 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(); + mockAnotherService.Setup(e => e.Touch(It.IsAny())); + var motherBoard1 = new MotherBoard(mockAnotherService.Object); + var result = motherBoard1.Touch(); + mockAnotherService.Verify(e => e.Touch(It.IsAny()), Times.Once()); } } } diff --git a/CourseApp/Car.cs b/CourseApp/Car.cs new file mode 100644 index 0000000..bcb5197 --- /dev/null +++ b/CourseApp/Car.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/CourseApp/MotherBoard.cs b/CourseApp/MotherBoard.cs new file mode 100644 index 0000000..6f83dcd --- /dev/null +++ b/CourseApp/MotherBoard.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 248bbe4..0c16613 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -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(); } } diff --git a/CourseApp/TouchPad.cs b/CourseApp/TouchPad.cs new file mode 100644 index 0000000..df0c568 --- /dev/null +++ b/CourseApp/TouchPad.cs @@ -0,0 +1,13 @@ +using System; + +namespace CourseApp +{ + public class TouchPad + { + public virtual int Touch(int times) + { + times++; + return times; + } + } +} \ No newline at end of file