-
Notifications
You must be signed in to change notification settings - Fork 128
Роман Косухин #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| using System.Collections.Generic; | ||
| using FakeItEasy; | ||
| using FluentAssertions; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace MockFramework | ||
|
|
@@ -44,17 +46,58 @@ public class ThingCache_Should | |
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| //thingService = A... | ||
| thingService = A.Fake<IThingService>(); | ||
| thingCache = new ThingCache(thingService); | ||
|
|
||
| Thing _ = null; | ||
| A.CallTo(() => thingService.TryRead(thingId1, out _)) | ||
| .Returns(true) | ||
| .AssignsOutAndRefParameters(thing1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я бы делал это не в сетапе, а в самих тестах. Сейчас по коду самого теста непонятно, что это за |
||
|
|
||
| A.CallTo(() => thingService.TryRead(thingId2, out _)) | ||
| .Returns(true) | ||
| .AssignsOutAndRefParameters(thing2); | ||
| } | ||
|
|
||
| // TODO: Написать простейший тест, а затем все остальные | ||
| // Live Template tt работает! | ||
|
|
||
| // Пример теста | ||
| [Test] | ||
| public void GiveMeAGoodNamePlease() | ||
| public void CallThingServiceOnce_OnFirstGet() | ||
| { | ||
| thingCache.Get(thingId1); | ||
|
|
||
| Thing _ = null; | ||
|
|
||
| A.CallTo(() => thingService.TryRead(thingId1, out _)).MustHaveHappenedOnceExactly(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void CallThingServiceOnce_OnTwoGet() | ||
| { | ||
| thingCache.Get(thingId1); | ||
| thingCache.Get(thingId1); | ||
|
|
||
| Thing _ = null; | ||
|
|
||
| A.CallTo(() => thingService.TryRead(thingId1, out _)).MustHaveHappenedOnceExactly(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ReturnRightThing_OnGet() | ||
| { | ||
| var thing = thingCache.Get(thingId1); | ||
|
|
||
| thing.Should().Be(thing1); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ReturnNull_OnEmptyId() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В коде нет отдельной обработки пустой строки: если по пустой строке что-то лежит, то оно вернётся. Тест все равно зелёный, потому что в данном случае по пустой строке ничего нет. Можно переделать его на тест, проверяющий, обратное (что пустая строка работает). И добавить тест, проверяющий, что если по произвольному ключу ничего нет, то вернется |
||
| { | ||
| var thing = thingCache.Get(""); | ||
|
|
||
| thing.Should().BeNull(); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут бы ещё пару тестов написать: проверить кейс, когда несколько сущностей, и проверить, кэшируется ли |
||
|
|
||
| /** Проверки в тестах | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В таких тестах неплохо бы ещё проверять, что не было вызова
TrySend: сайд-эффект здесь важнее, чем возвращаемое значение