Skip to content

Commit

Permalink
Simplified exceptions and updated some gaps in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jregnier committed Jan 5, 2021
1 parent d51724c commit 858ed9c
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 371 deletions.
2 changes: 1 addition & 1 deletion build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ internal class Build : NukeBuild
.SetAssembly(assemblyPath)
.SetOutput(ArtifactsDirectory / "coverage.cobertura.xml")
.SetFormat(CoverletOutputFormat.cobertura)
.SetExclude("Properties"));
.SetExcludeByFile(@"**/Resources.Designer.cs"));
});

public static int Main() => Execute<Build>(x => x.Pack);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

28 changes: 0 additions & 28 deletions src/MtgApiManager.Lib.Test/Core/MtgApiExceptionTest.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MtgApiManager.Lib.Core.Exceptions;
using MtgApiManager.Lib.Core;
using Xunit;
namespace MtgApiManager.Lib.Test.Core.Exceptions
{
Expand All @@ -11,7 +11,7 @@ public void Message_Correct()
const string MESSAGE = "testing";

// When
var exception = new MtgExceptionBase(MESSAGE);
var exception = new MtgApiException(MESSAGE);

// Then
Assert.StartsWith(Properties.Resources.MtgError, exception.Message);
Expand Down
1 change: 0 additions & 1 deletion src/MtgApiManager.Lib.Test/Service/CardServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Moq;
using MtgApiManager.Lib.Core;
using MtgApiManager.Lib.Dto;
using MtgApiManager.Lib.Dto.Set;
using MtgApiManager.Lib.Model;
using MtgApiManager.Lib.Service;
using Xunit;
Expand Down
67 changes: 66 additions & 1 deletion src/MtgApiManager.Lib.Test/Service/ServiceBaseTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Flurl.Http.Testing;
using Flurl.Util;
Expand Down Expand Up @@ -92,7 +95,7 @@ public async Task CallWebServiceGet_RateLimitOn_Success()
}

[Fact]
public void Constructor_calls_ResetCurrentUrl()
public void Constructor_Calls_ResetCurrentUrl()
{
// arrange
// act
Expand Down Expand Up @@ -164,5 +167,67 @@ public void ResetCurrentUrl_ResetsUrl_Success()
// assert
Assert.Equal(2, service.CurrentQueryUrlTestProp.PathSegments.Count);
}

[Theory]
[ClassData(typeof(ErrorTestData))]
public async Task CallWebServiceGet_ReturnsException_Throws(int id, string description)
{
// arrange
var URL = new Uri("http://fake/url");

_mockRateLimit.Setup(x => x.IsTurnedOn).Returns(false);

using var httpTest = new HttpTest();
httpTest.RespondWith("error", id);

var service = new ServiceBaseTestObject(
_mockHeaderManager.Object,
_mockModelMapper.Object,
_mockRateLimit.Object);

// act
// assert
var result = await Assert.ThrowsAsync<MtgApiException>(
() => service.CallWebServiceGetTestMethod(URL));
Assert.EndsWith(description, result.Message);
_mockRepository.VerifyAll();
}

[Fact]
public async Task CallWebServiceGet_ExceptionStatusCodeUnknown_ThrowsBadRequest()
{
// arrange
const string ERROR_MESSAGE = "something bad happened";

var URL = new Uri("http://fake/url");

_mockRateLimit.Setup(x => x.IsTurnedOn).Returns(false);

using var httpTest = new HttpTest();
httpTest.RespondWith(ERROR_MESSAGE, 410);

var service = new ServiceBaseTestObject(
_mockHeaderManager.Object,
_mockModelMapper.Object,
_mockRateLimit.Object);

// act
// assert
var result = await Assert.ThrowsAsync<MtgApiException>(
() => service.CallWebServiceGetTestMethod(URL));
Assert.EndsWith(ERROR_MESSAGE, result.Message);
_mockRepository.VerifyAll();
}

public class ErrorTestData : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator() =>
Enumeration.GetAll<MtgApiError>()
.Where(x => x.Id != MtgApiError.None.Id)
.Select(x => new object[] { x.Id, x.Description })
.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
}
38 changes: 38 additions & 0 deletions src/MtgApiManager.Lib.Test/Service/SetQueryParameterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using MtgApiManager.Lib.Service;
using Xunit;

namespace MtgApiManager.Lib.Test.Service
{
public class SetQueryParameterTests
{
[Fact]
public void SetQueryParameter_BlockSet_Success()
{
// arrange
const string BLOCK = "block1";
var queryParams = new SetQueryParameter
{
// act
Block = BLOCK
};

// assert
Assert.Equal(BLOCK, queryParams.Block);
}

[Fact]
public void SetQueryParameter_NameSet_Success()
{
// arrange
const string NAME = "name1";
var queryParams = new SetQueryParameter
{
// act
Name = NAME
};

// assert
Assert.Equal(NAME, queryParams.Name);
}
}
}
17 changes: 0 additions & 17 deletions src/MtgApiManager.Lib/Core/Exceptions/BadRequestException.cs

This file was deleted.

17 changes: 0 additions & 17 deletions src/MtgApiManager.Lib/Core/Exceptions/ForbiddenException.cs

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions src/MtgApiManager.Lib/Core/Exceptions/MtgExceptionBase.cs

This file was deleted.

Loading

0 comments on commit 858ed9c

Please sign in to comment.