-
Notifications
You must be signed in to change notification settings - Fork 236
Тимур Бабаев #216
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
Open
truefolder
wants to merge
10
commits into
kontur-courses:master
Choose a base branch
from
truefolder:homework
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Тимур Бабаев #216
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0fd6936
Скопировал проект из прошлой задачи
truefolder 73a44ec
Добавил класс и структуру Result
truefolder 6682761
Начало работы над переносом возвращаемых значений на Result: поменял …
truefolder c9d12f5
Не всё стоит оборачивать в Result
truefolder 8f4e2f0
Поменял раскраску и препроцессоры слов
truefolder 4a2ea16
Изменения со всем кроме Generator'а, тестов и клиента
truefolder 08da6cc
TagCloudGenerator и вывод ошибки в клиенте
truefolder 299f6f7
Поправил тесты
truefolder c1b89c7
Правки по ПР
truefolder 267ca1d
Правки по ПР
truefolder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ public static Result<T> Ok<T>(T value) | |
| { | ||
| return new Result<T>(null, value); | ||
| } | ||
|
|
||
| public static Result<None> Ok() | ||
|
Comment on lines
+35
to
+37
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. немного форматирование
Author
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. Поправил |
||
| { | ||
| return Ok<None>(null); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| using FluentAssertions; | ||
| using TagCloud.ResultModel; | ||
|
|
||
| namespace TagCloudTests; | ||
|
|
||
| public class ResultTests | ||
| { | ||
| [Test] | ||
| public void Ok_ShouldBeSuccessAndContainValue_WhenValueIsProvided() | ||
| { | ||
| var result = Result.Ok(52); | ||
|
|
||
| result.IsSuccess.Should().BeTrue(); | ||
| result.GetValueOrThrow().Should().Be(52); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Fail_ShouldNotBeSuccessAndContainError_WhenErrorIsProvided() | ||
| { | ||
| var result = Result.Fail<int>("some error"); | ||
|
|
||
| result.IsSuccess.Should().BeFalse(); | ||
| result.Error.Should().Be("some error"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void GetValueOrThrow_ShouldThrow_WhenFail() | ||
| { | ||
| var result = Result.Fail<int>("error"); | ||
|
|
||
| Action action = () => result.GetValueOrThrow(); | ||
|
|
||
| action.Should().Throw<InvalidOperationException>(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Then_ShouldTransformValue_WhenSuccess() | ||
| { | ||
| var result = Result.Ok(3) | ||
| .Then(x => x * 3); | ||
|
|
||
| result.IsSuccess.Should().BeTrue(); | ||
| result.GetValueOrThrow().Should().Be(9); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Then_ShouldNotCallNextAction_WhenFail() | ||
| { | ||
| var isCalled = false; | ||
|
|
||
| var result = Result.Fail<int>("error") | ||
| .Then(x => | ||
| { | ||
| isCalled = true; | ||
| return x * 2; | ||
| }); | ||
|
|
||
| result.IsSuccess.Should().BeFalse(); | ||
| isCalled.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Of_ShouldCatchExceptionAndReturnFail_WhenExceptionIsInside() | ||
| { | ||
| var result = Result.Of<int>(() => throw new Exception("error")); | ||
|
|
||
| result.IsSuccess.Should().BeFalse(); | ||
| result.Error.Should().Contain("error"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void RefineError_ShouldPrefixErrorMessage() | ||
| { | ||
| var result = Result.Fail<int>("error") | ||
| .RefineError("refined error"); | ||
|
|
||
| result.IsSuccess.Should().BeFalse(); | ||
| result.Error.Should().Be("refined error. error"); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
А зачем этот .Then(Result.Ok) появился?
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.
И пробегись по остальным местам где была такая же конструкция .Then(x => x)