Skip to content

Commit

Permalink
fixed few issues
Browse files Browse the repository at this point in the history
  • Loading branch information
daerup committed Feb 29, 2024
1 parent fb8167e commit 54915e2
Show file tree
Hide file tree
Showing 54 changed files with 319 additions and 430 deletions.
16 changes: 6 additions & 10 deletions Schnacc.Authorization.UnitTests/AuthorizationApiTest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using FluentAssertions;
using Schnacc.Authorization.Exception;
using Xunit;

namespace Schnacc.Authorization.UnitTests
{
using System;

using FluentAssertions;

using Schnacc.Authorization.Exception;

using Xunit;

public class AuthorizationApiTest
{
private AuthorizationApi testee = new AuthorizationApi();
Expand All @@ -30,7 +26,7 @@ private async void UserCanSignInWithEmailAndPassword()
}

[Fact]
private async void WhenNotRegisteredUserCanNotSignIn()
private void WhenNotRegisteredUserCanNotSignIn()
{
// Arrange
string email = "hans.muster@notRegistered.ch";
Expand Down
23 changes: 9 additions & 14 deletions Schnacc.Authorization/AuthorizationApi.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System.Threading.Tasks;
using Firebase.Auth;
using Schnacc.Authorization.Exception;

namespace Schnacc.Authorization
{
using Firebase.Auth;

using Exception;

public class AuthorizationApi
{
private readonly FirebaseAuthProvider authProvider;
Expand All @@ -15,10 +13,7 @@ public class AuthorizationApi
public bool EmailIsVerified =>
this.authProvider.GetUserAsync(this.AccessToken).GetAwaiter().GetResult().IsEmailVerified;

public AuthorizationApi()
{
this.authProvider = new FirebaseAuthProvider(new FirebaseConfig(AuthConfig.ApiKey));
}
public AuthorizationApi() => this.authProvider = new FirebaseAuthProvider(new FirebaseConfig(AuthConfig.ApiKey));

public async Task RegisterWithEmail(string email, string password, string displayName)
{
Expand All @@ -28,19 +23,19 @@ public async Task RegisterWithEmail(string email, string password, string displ
}
catch (FirebaseAuthException e) when (e.Reason == AuthErrorReason.EmailExists)
{
throw new UserAlreadyRegisteredException($"There is already a user with this email registered, try another one or Login");
throw new UserAlreadyRegisteredException("There is already a user with this email registered, try another one or Login");
}
catch (FirebaseAuthException e) when (e.Reason == AuthErrorReason.WeakPassword)
{
throw new PasswordTooWeakException($"Yikes, your password is too weak...");
throw new PasswordTooWeakException("Yikes, your password is too weak...");
}
catch (FirebaseAuthException e) when (e.Reason == AuthErrorReason.InvalidEmailAddress)
{
throw new InvalidEmailException($"Are you kidding me? '{email}' is not an email...");
}
catch (FirebaseAuthException e) when (e.Reason == AuthErrorReason.Undefined)
{
throw new UndifinedException($"Looks like there was an Error. Probably your Internet Connection");
throw new UndifinedException("Looks like there was an Error. Probably your Internet Connection");
}
catch (System.Exception e)
{
Expand All @@ -63,19 +58,19 @@ public async Task<string> SignInWithEmail(string email, string password)
}
catch (FirebaseAuthException e) when (e.Reason == AuthErrorReason.WrongPassword)
{
throw new WrongLoginCredentialsException($"Your login credentials are incorrect...");
throw new WrongLoginCredentialsException("Your login credentials are incorrect...");
}
catch (FirebaseAuthException e) when (e.Reason == AuthErrorReason.InvalidEmailAddress)
{
throw new InvalidEmailException($"Are you kidding me? '{email}' is not an email...");
}
catch (FirebaseAuthException e) when (e.Reason == AuthErrorReason.TooManyAttemptsTryLater)
{
throw new TooManyTriesException($"Chill my dude, you are doing too much. Try again later");
throw new TooManyTriesException("Chill my dude, you are doing too much. Try again later");
}
catch (FirebaseAuthException e) when (e.Reason == AuthErrorReason.Undefined)
{
throw new UndifinedException($"Looks like there was an Error. Probably your Internet Connection");
throw new UndifinedException("Looks like there was an Error. Probably your Internet Connection");
}
catch (System.Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
namespace Schnacc.Authorization.Exception
{
using System;

public class UserNotRegisteredException : Exception, IFirebaseHandledException
public class UserNotRegisteredException : System.Exception, IFirebaseHandledException
{
internal UserNotRegisteredException(string message) : base(message)
{
Expand Down
14 changes: 6 additions & 8 deletions Schnacc.Database.UnitTests/DatabaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
namespace Schnacc.Database.UnitTests
{
using System.Collections.Generic;
using FluentAssertions;

using Schnacc.Authorization;

using Xunit;
using System.Collections.Generic;
using FluentAssertions;
using Schnacc.Authorization;
using Xunit;

namespace Schnacc.Database.UnitTests
{
public class DatabaseTest
{
private Database testee;
Expand Down
15 changes: 7 additions & 8 deletions Schnacc.Database/Database.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Firebase.Database.Streaming;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Firebase.Database;
using Firebase.Database.Query;
using Firebase.Database.Streaming;

namespace Schnacc.Database
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Firebase.Database;
using Firebase.Database.Query;

public class Database
{
private readonly FirebaseClient firebaseClient;
Expand Down
6 changes: 3 additions & 3 deletions Schnacc.Database/Highscore.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Schnacc.Database
{
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace Schnacc.Database
{
public class Highscore
{
public Highscore()
Expand Down
45 changes: 19 additions & 26 deletions Schnacc.Domain.IntegrationTests/PlayareaTest.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
namespace Schnacc.Domain.IntegrationTests
using FakeItEasy;
using FakeItEasy.Core;
using FluentAssertions;
using Schnacc.Domain.Food;
using Schnacc.Domain.Playarea;
using Schnacc.Domain.Snake;
using Xbehave;

namespace Schnacc.Domain.IntegrationTests
{
using FakeItEasy;
using FakeItEasy.Core;
using FluentAssertions;

using Food;

using Playarea;

using Snake;

using Xbehave;

public class PlayareaTest
{
private Playarea testee;
private Playarea.Playarea testee;

[Background]
public void SetUp()
Expand All @@ -32,7 +28,7 @@ private void WhenTheSnakeCollidesInFruitItGrows()
"And given the food will pops up in front of snake head"
.x(() => A.CallTo(() => foodFactory.CreateRandomFoodBetweenBoundaries(A<Position>.Ignored)).Returns(new Apple(new Position(5, 4))).Once());
"And given a play area with boundaries 10 and 5"
.x(() => this.testee = new Playarea(new PlayareaSize(10, 5), foodFactory));
.x(() => this.testee = new Playarea.Playarea(new PlayareaSize(10, 5), foodFactory));
"And given the snake at position row 5 and column 2"
.x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(5, 2)));
"And given the food is in front of the snake"
Expand Down Expand Up @@ -62,7 +58,7 @@ private void SnakeCannotBeResetUnlessTheGameIsOver()
"Given a food factory"
.x(() => foodFactory = A.Fake<IFoodFactory>());
"And given a play area with size 4 by 4"
.x(() => this.testee = new Playarea(new PlayareaSize(4, 4), foodFactory));
.x(() => this.testee = new Playarea.Playarea(new PlayareaSize(4, 4), foodFactory));
"And given the snake at position row 2 and column 2"
.x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 2)));
"And the game state is start"
Expand Down Expand Up @@ -107,7 +103,7 @@ private void SnakeCannotMoveWhenTheGameIsOver()
"Given a food factory"
.x(() => foodFactory = A.Dummy<IFoodFactory>());
"And given a play area"
.x(() => this.testee = new Playarea(new PlayareaSize(4, 5), foodFactory));
.x(() => this.testee = new Playarea.Playarea(new PlayareaSize(4, 5), foodFactory));
"And given the snake at position row 2 and column 1"
.x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 2)));
"And the game state is start"
Expand Down Expand Up @@ -155,7 +151,7 @@ private void GameIsOverWhenSnakeCollidesWithRightWall()
"Given a food factory"
.x(() => foodFactory = A.Fake<IFoodFactory>());
"And given a play area with boundaries 4 and 5"
.x(() => this.testee = new Playarea(new PlayareaSize(4, 5), foodFactory));
.x(() => this.testee = new Playarea.Playarea(new PlayareaSize(4, 5), foodFactory));
"And given the snake at position row 2 and column 2"
.x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 2)));
"And given the snake is facing rightwards"
Expand Down Expand Up @@ -191,7 +187,7 @@ private void GameIsOverWhenSnakeCollidesWithLeftWall()
"Given a food factory"
.x(() => foodFactory = A.Fake<IFoodFactory>());
"And given a play area with boundaries 4 and 4"
.x(() => this.testee = new Playarea(new PlayareaSize(4, 4), foodFactory));
.x(() => this.testee = new Playarea.Playarea(new PlayareaSize(4, 4), foodFactory));
"And given the snake at position row 2 and column 2"
.x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 2)));
"And given the snake is facing leftwards"
Expand Down Expand Up @@ -227,7 +223,7 @@ private void GameIsOverWhenSnakeCollidesWithTopWall()
"Given a food factory"
.x(() => foodFactory = A.Fake<IFoodFactory>());
"And given a play area with boundaries 4 and 4"
.x(() => this.testee = new Playarea(new PlayareaSize(4, 4), foodFactory));
.x(() => this.testee = new Playarea.Playarea(new PlayareaSize(4, 4), foodFactory));
"And given the snake at position row 2 and column 2"
.x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 2)));
"And given the snake is facing upwards"
Expand Down Expand Up @@ -262,7 +258,7 @@ private void GameIsOverWhenSnakeCollidesWithBottomWall()
"Given a food factory"
.x(() => foodFactory = A.Fake<IFoodFactory>());
"And given a play area with boundaries 5 and 5"
.x(() => this.testee = new Playarea(new PlayareaSize(5, 5), foodFactory));
.x(() => this.testee = new Playarea.Playarea(new PlayareaSize(5, 5), foodFactory));
"And given the snake at position row 2 and column 2"
.x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 2)));
"And given the snake is facing downwards"
Expand Down Expand Up @@ -300,7 +296,7 @@ private void GameIsOverWhenSnakeCollidesWithItself()
.x(() => A.CallTo(() => foodFactory.CreateRandomFoodBetweenBoundaries(A<Position>.Ignored))
.ReturnsLazily(this.CalculateNewFoodPosition));
"And given a play area with boundaries 10 and 12"
.x(() => this.testee = new Playarea(new PlayareaSize(10, 12), foodFactory));
.x(() => this.testee = new Playarea.Playarea(new PlayareaSize(10, 12), foodFactory));
"And given the snake at position row 5 and column 6"
.x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(5, 6)));
"And given the food is actually in front of the snake"
Expand Down Expand Up @@ -367,9 +363,6 @@ private void GameIsOverWhenSnakeCollidesWithItself()
.x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(4, 9)));
}

private Food CalculateNewFoodPosition(IFakeObjectCall arg)
{
return this.testee != null ? new Apple(new Position(5, this.testee.Snake.Head.Position.Column + 1)) : new Apple(new Position(5, 7));
}
private Food.Food CalculateNewFoodPosition(IFakeObjectCall arg) => this.testee != null ? new Apple(new Position(5, this.testee.Snake.Head.Position.Column + 1)) : new Apple(new Position(5, 7));
}
}
18 changes: 9 additions & 9 deletions Schnacc.Domain.IntegrationTests/SnakeMovementTest.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
namespace Schnacc.Domain.IntegrationTests
{
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using FluentAssertions;
using Snake;
using Xbehave;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using FluentAssertions;
using Schnacc.Domain.Snake;
using Xbehave;

namespace Schnacc.Domain.IntegrationTests
{
[SuppressMessage("ReSharper", "TooManyDeclarations")]
public class SnakeMovementTest
{
private Snake testee;
private Snake.Snake testee;

private void GivingASnakeWithABodyFacingInACertainDirection(int startRow, int startColumn, Direction certainDirection)
{
"Given a snake"
.x(() => this.testee = new Snake(new Position(startRow, startColumn)));
.x(() => this.testee = new Snake.Snake(new Position(startRow, startColumn)));
"And the snake is facing right"
.x(() => this.testee.UpdateFacingDirection(certainDirection));
"And the snake has a body containing one body part"
Expand Down
17 changes: 7 additions & 10 deletions Schnacc.Domain.UnitTests/Food/AppleTest.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
namespace Schnacc.Domain.UnitTests.Food
{
using FakeItEasy;

using FluentAssertions;

using Schnacc.Domain.Food;
using Schnacc.Domain.Snake;

using Xunit;
using FakeItEasy;
using FluentAssertions;
using Schnacc.Domain.Food;
using Schnacc.Domain.Snake;
using Xunit;

namespace Schnacc.Domain.UnitTests.Food
{
public class AppleTest
{
private readonly IFood testee = new Apple(A.Dummy<Position>());
Expand Down
17 changes: 7 additions & 10 deletions Schnacc.Domain.UnitTests/Food/BananaTest.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
namespace Schnacc.Domain.UnitTests.Food
{
using FakeItEasy;

using FluentAssertions;

using Schnacc.Domain.Food;
using Schnacc.Domain.Snake;

using Xunit;
using FakeItEasy;
using FluentAssertions;
using Schnacc.Domain.Food;
using Schnacc.Domain.Snake;
using Xunit;

namespace Schnacc.Domain.UnitTests.Food
{
public class BananaTest
{
private readonly IFood testee = new Banana(A.Dummy<Position>());
Expand Down
22 changes: 9 additions & 13 deletions Schnacc.Domain.UnitTests/Food/FoodFactoryTest.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
namespace Schnacc.Domain.UnitTests.Food
using System;
using FluentAssertions;
using FsCheck;
using FsCheck.Xunit;
using Schnacc.Domain.Food;
using Schnacc.Domain.Snake;
using Xunit;

namespace Schnacc.Domain.UnitTests.Food
{
using System;

using FluentAssertions;

using FsCheck;
using FsCheck.Xunit;

using Schnacc.Domain.Food;
using Schnacc.Domain.Snake;

using Xunit;

public class FoodFactoryTest
{
private FoodFactory testee;
Expand Down
Loading

0 comments on commit 54915e2

Please sign in to comment.