Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
87 changes: 66 additions & 21 deletions FileSender/FileSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public class FileSender_Should
private readonly X509Certificate certificate = new X509Certificate();
private File file;
private byte[] signedContent;
private Document document;

private File invalidFile;
private byte[] invalidSignedContent;
private Document invalidDocument;

private File couldNotSendFile;
private byte[] couldNotSendSignedContent;
private Document couldNotSendDocument;

[SetUp]
public void SetUp()
Expand All @@ -89,71 +98,107 @@ public void SetUp()
sender = A.Fake<ISender>();
recognizer = A.Fake<IRecognizer>();
fileSender = new FileSender(cryptographer, sender, recognizer);
}

[TestCase("4.0")]
[TestCase("3.1")]
public void Send_WhenGoodFormat(string format)
{
var document = new Document(file.Name, file.Content, DateTime.Now, format);
document = new Document(file.Name, file.Content, DateTime.Now, "4.0");
A.CallTo(() => recognizer.TryRecognize(file, out document))
.Returns(true);
A.CallTo(() => cryptographer.Sign(document.Content, certificate))
.Returns(signedContent);
A.CallTo(() => sender.TrySend(signedContent))
.Returns(true);


invalidFile = new File("invalidFile", new byte[] { 1, 2, 3 });
invalidSignedContent = new byte[] { 1, 7 };
invalidDocument = new Document(invalidFile.Name, invalidFile.Content, DateTime.Now, "111.222");

A.CallTo(() => recognizer.TryRecognize(invalidFile, out invalidDocument))
.Returns(true);
A.CallTo(() => cryptographer.Sign(invalidDocument.Content, certificate))
.Returns(invalidSignedContent);
A.CallTo(() => sender.TrySend(invalidSignedContent))
.Returns(true);


couldNotSendFile = new File("invalidFile", new byte[] { 1, 2, 3 });
couldNotSendSignedContent = new byte[] { 1, 7 };
couldNotSendDocument = new Document(couldNotSendFile.Name, couldNotSendFile.Content, DateTime.Now, "4.0");

A.CallTo(() => recognizer.TryRecognize(couldNotSendFile, out couldNotSendDocument))
.Returns(true);
A.CallTo(() => cryptographer.Sign(couldNotSendDocument.Content, certificate))
.Returns(couldNotSendSignedContent);
A.CallTo(() => sender.TrySend(couldNotSendSignedContent))
.Returns(false);
}

[TestCase("4.0")]
[TestCase("3.1")]
public void Send_WhenGoodFormat(string format)
{
document.Format = format;

fileSender.SendFiles(new[] {file}, certificate)
.SkippedFiles.Should().BeEmpty();
}

[Test]
[Ignore("Not implemented")]
public void Skip_WhenBadFormat()
[TestCase("111.222")]
public void Skip_WhenBadFormat(string format)
{
throw new NotImplementedException();
document.Format = format;

fileSender.SendFiles(new[] { file }, certificate)
.SkippedFiles.Should().HaveCount(1);
}

[Test]
[Ignore("Not implemented")]
public void Skip_WhenOlderThanAMonth()
{
throw new NotImplementedException();
document.Created = document.Created.AddMonths(-1).AddDays(-1);

fileSender.SendFiles(new[] { file }, certificate)
.SkippedFiles.Should().HaveCount(1);
}

[Test]
[Ignore("Not implemented")]
public void Send_WhenYoungerThanAMonth()
{
throw new NotImplementedException();
document.Created = document.Created.AddMonths(-1).AddDays(1);

fileSender.SendFiles(new[] { file }, certificate)
.SkippedFiles.Should().BeEmpty();
}

[Test]
[Ignore("Not implemented")]
public void Skip_WhenSendFails()
{
throw new NotImplementedException();
fileSender.SendFiles(new[] { couldNotSendFile }, certificate)
.SkippedFiles.Should().HaveCount(1);
}

[Test]
[Ignore("Not implemented")]
public void Skip_WhenNotRecognized()
{
throw new NotImplementedException();
A.CallTo(() => recognizer.TryRecognize(file, out document))
.Returns(false);

fileSender.SendFiles(new[] { file }, certificate)
.SkippedFiles.Should().HaveCount(1);
}

[Test]
[Ignore("Not implemented")]
public void IndependentlySend_WhenSeveralFilesAndSomeAreInvalid()
{
throw new NotImplementedException();
fileSender.SendFiles(new[] { file, invalidFile }, certificate)
.SkippedFiles.Should().HaveCount(1);
}

[Test]
[Ignore("Not implemented")]
public void IndependentlySend_WhenSeveralFilesAndSomeCouldNotSend()
{
throw new NotImplementedException();
fileSender.SendFiles(new[] { file, couldNotSendFile }, certificate)
.SkippedFiles.Should().HaveCount(1);
}
}
}
1 change: 1 addition & 0 deletions FileSender/FileSender.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
</ItemGroup>

<ItemGroup>
Expand Down
27 changes: 25 additions & 2 deletions ThingCache/ThingCache.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using FakeItEasy;
using NUnit.Framework;

namespace MockFramework
Expand Down Expand Up @@ -40,11 +41,17 @@ public class ThingCache_Should
private const string thingId2 = "CoolBoots";
private Thing thing2 = new Thing(thingId2);

private const string thingIdNotExisted = "NotExisted";
private Thing thing3 = null;

// Метод, помеченный атрибутом SetUp, выполняется перед каждым тестов
[SetUp]
public void SetUp()
{
//thingService = A...
thingService = A.Fake<IThingService>();
A.CallTo(() => thingService.TryRead(thingId1, out thing1)).Returns(true);
A.CallTo(() => thingService.TryRead(thingId2, out thing2)).Returns(true);
A.CallTo(() => thingService.TryRead(thingIdNotExisted, out thing3)).Returns(false);
thingCache = new ThingCache(thingService);
}

Expand All @@ -53,8 +60,24 @@ public void SetUp()

// Пример теста
[Test]
public void GiveMeAGoodNamePlease()
public void ThingCache_Get_ReturnsCorrectValue()
{
var actualValue = thingCache.Get(thingId1);
Assert.That(actualValue, Is.EqualTo(thing1));
}

[Test]
public void ThingCache_Get_ReturnsNoValue()
{
var notExistedValue = thingCache.Get(thingIdNotExisted);
Assert.That(notExistedValue, Is.Null);
}

[Test]
public void ThingCache_Get_MethodCallingHappened()
{
thingCache.Get(thingId1);
A.CallTo(() => thingService.TryRead(thingId1, out thing1)).MustHaveHappenedOnceExactly();
}

/** Проверки в тестах
Expand Down
1 change: 1 addition & 0 deletions ThingCache/ThingCache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
</ItemGroup>

<ItemGroup>
Expand Down