Skip to content

Commit 7213756

Browse files
committed
Fixed failing unit tests after the merge (#353)
1 parent 4e93a43 commit 7213756

File tree

18 files changed

+120
-158
lines changed

18 files changed

+120
-158
lines changed

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/CaughtExceptions/ExceptionTestBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public IAndExceptionTestBuilder OfType(Type exceptionType)
2929
if (Reflection.AreDifferentTypes(exceptionType, actualExceptionType))
3030
{
3131
var (expectedExceptionName, actualExceptionName) =
32-
(expectedExceptionType, actualExceptionType).GetTypeComparisonNames();
32+
(exceptionType, actualExceptionType).GetTypeComparisonNames();
3333

3434
throw new InvalidExceptionAssertionException(string.Format(
3535
"{0} {1}, but instead received {2}.",

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/Application/TestApplicationServices.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Services;
99
using System;
1010
using System.Collections.Generic;
11-
using System.IO;
1211
using System.Linq;
1312
using System.Reflection;
1413
using Utilities.Extensions;

src/MyTested.AspNetCore.Mvc.Abstractions/Utilities/Validators/DictionaryValidator.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ public static void ValidateStringKeyAndValue(
4646
public static void ValidateValueOfType<TValue>(
4747
string name,
4848
IDictionary<string, object> dictionary,
49-
Action<string, string, string> failedValidationAction)
50-
{
51-
ValidateValueOfType<TValue>(name, dictionary.Values, failedValidationAction);
52-
}
49+
Action<string, string, string> failedValidationAction)
50+
=> ValidateValueOfType<TValue>(name, dictionary.Values, failedValidationAction);
5351

5452
public static void ValidateValueOfType(
5553
string name,
@@ -67,21 +65,22 @@ public static void ValidateValueOfType(
6765
string name,
6866
IDictionary<object, object> dictionary,
6967
Action<string, string, string> failedValidationAction,
70-
Type valueType)
71-
=> ValidateValueOfType(name, dictionary.Values, failedValidationAction, valueType);
68+
Type expectedType)
69+
=> ValidateValueOfType(name, dictionary.Values, failedValidationAction, expectedType);
7270

7371
public static void ValidateStringKeyAndValueOfType(
7472
string name,
7573
IDictionary<string, object> dictionary,
7674
string key,
7775
Action<string, string, string> failedValidationAction,
78-
Type valueType)
76+
Type expectedType)
7977
{
8078
var entryExists = dictionary.ContainsKey(key);
81-
var actualValue = entryExists ? dictionary[key] : null;
8279

80+
var actualValue = entryExists ? dictionary[key] : null;
8381
var actualType = actualValue?.GetType();
84-
if (!entryExists || Reflection.AreDifferentTypes(valueType, actualType))
82+
83+
if (!entryExists || Reflection.AreDifferentTypes(expectedType, actualType))
8584
{
8685
var (expectedTypeName, actualTypeName) = (expectedType, actualType).GetTypeComparisonNames();
8786

@@ -148,15 +147,15 @@ private static void ValidateValueOfType(
148147
string name,
149148
ICollection<object> values,
150149
Action<string, string, string> failedValidationAction,
151-
Type valueType)
150+
Type expectedType)
152151
{
153-
var entryOfSameType = values.FirstOrDefault(arg => arg.GetType() == valueType);
152+
var entryOfSameType = values.FirstOrDefault(arg => arg.GetType() == expectedType);
154153

155154
if (entryOfSameType == null)
156155
{
157156
failedValidationAction(
158157
name,
159-
$"to have at least one entry of {valueType.ToFriendlyTypeName()} type",
158+
$"to have at least one entry of {expectedType.ToFriendlyTypeName()} type",
160159
"none was found");
161160
}
162161
}

src/MyTested.AspNetCore.Mvc.Caching/Builders/Data/MemoryCache/MemoryCacheTestBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ public IAndMemoryCacheTestBuilder ContainingEntryOfType<TValue>()
6969
=> this.ContainingEntryOfType(typeof(TValue));
7070

7171
/// <inheritdoc />
72-
public IAndMemoryCacheTestBuilder ContainingEntryOfType(object key, Type valueType)
72+
public IAndMemoryCacheTestBuilder ContainingEntryOfType(object key, Type expectedType)
7373
{
7474
var value = this.GetValue(key);
7575
var actualType = value.GetType();
7676

77-
if (Reflection.AreDifferentTypes(valueType, actualType))
77+
if (Reflection.AreDifferentTypes(expectedType, actualType))
7878
{
7979
var (expectedTypeName, actualTypeName) = (expectedType, actualType).GetTypeComparisonNames();
8080

src/MyTested.AspNetCore.Mvc.ViewComponents.Results/ViewTestBuilderViewComponentsExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public static IAndViewTestBuilder WithViewEngineOfType<TViewEngine>(
103103
/// <param name="viewEngineType"></param>
104104
/// <returns>The same <see cref="IAndViewTestBuilder"/>.</returns>
105105
public static IAndViewTestBuilder WithViewEngineOfType(
106-
this IViewTestBuilder viewTestBuilder,Type viewEngineType)
106+
this IViewTestBuilder viewTestBuilder,
107+
Type viewEngineType)
107108
{
108109
var actualBuilder = GetActualBuilder(viewTestBuilder);
109110

@@ -113,7 +114,7 @@ public static IAndViewTestBuilder WithViewEngineOfType(
113114
|| Reflection.AreDifferentTypes(viewEngineType, actualViewEngineType))
114115
{
115116
var (expectedViewEngineTypeName, actualViewEngineTypeName) =
116-
(expectedViewEngineType, actualViewEngineType).GetTypeComparisonNames();
117+
(viewEngineType, actualViewEngineType).GetTypeComparisonNames();
117118

118119
throw ViewViewComponentResultAssertionException.ForViewEngineType(
119120
actualBuilder.TestContext.ExceptionMessagePrefix,

test/MyTested.AspNetCore.Mvc.Controllers.Test/PluginsTests/ControllersTestPluginTest.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace MyTested.AspNetCore.Mvc.Test.PluginsTests
22
{
33
using System;
4-
using Microsoft.AspNetCore.Mvc.Internal;
4+
using Microsoft.AspNetCore.Mvc.Controllers;
55
using Microsoft.Extensions.DependencyInjection;
66
using Microsoft.Extensions.Options;
77
using Plugins;
@@ -36,10 +36,7 @@ public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollectionForDefaultRegi
3636

3737
testPlugin.DefaultServiceRegistrationDelegate(serviceCollection);
3838

39-
var methodReturnType = testPlugin.DefaultServiceRegistrationDelegate.Method.ReturnType.Name;
40-
41-
Assert.True(methodReturnType == "Void");
42-
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(MiddlewareFilterBuilder));
39+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(IControllerFactory));
4340
}
4441

4542
[Fact]
@@ -50,9 +47,6 @@ public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()
5047

5148
testPlugin.ServiceRegistrationDelegate(serviceCollection);
5249

53-
var methodReturnType = testPlugin.ServiceRegistrationDelegate.Method.ReturnType.Name;
54-
55-
Assert.True(methodReturnType == "Void");
5650
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(IOptions<>));
5751
}
5852
}

test/MyTested.AspNetCore.Mvc.Controllers.Views.Test/PluginTests/ViewActionResultTestPluginTest.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace MyTested.AspNetCore.Mvc.Test.PluginTests
22
{
33
using System;
4-
using Microsoft.AspNetCore.Mvc.Formatters.Json.Internal;
4+
using Microsoft.AspNetCore.Mvc.Controllers;
55
using Microsoft.Extensions.DependencyInjection;
66
using Plugins;
77
using Xunit;
@@ -34,10 +34,7 @@ public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()
3434

3535
testPlugin.DefaultServiceRegistrationDelegate(serviceCollection);
3636

37-
var methodReturnType = testPlugin.DefaultServiceRegistrationDelegate.Method.ReturnType.Name;
38-
39-
Assert.True(methodReturnType == "Void");
40-
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(JsonResultExecutor));
37+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(IControllerFactory));
4138
}
4239
}
4340
}

test/MyTested.AspNetCore.Mvc.EntityFrameworkCore.Test/BuildersTests/ControllersTests/ControllerBuilderTests.cs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -490,26 +490,28 @@ public void WithoutDataDeletingWholeDatabaseReturnsCorrectData()
490490
[Fact]
491491
public void WithoutDataThrowsExceptionWhenNullIsProvided()
492492
{
493-
Test.AssertException<ArgumentNullException>(() =>
494-
{
495-
MyApplication
496-
.StartsFrom<TestStartup>()
497-
.WithServices(services => services.AddDbContext<CustomDbContext>());
498-
499-
var model = new CustomModel
493+
Test.AssertException<ArgumentNullException>(
494+
() =>
500495
{
501-
Id = 1,
502-
Name = "Test"
503-
};
504-
505-
MyController<DbContextController>
506-
.Instance()
507-
.WithData(model)
508-
.WithoutData(default(List<object>))
509-
.Calling(c => c.Get(model.Id))
510-
.ShouldReturn()
511-
.NotFound();
512-
}, "Value cannot be null.\r\nParameter name: entities");
496+
MyApplication
497+
.StartsFrom<TestStartup>()
498+
.WithServices(services => services.AddDbContext<CustomDbContext>());
499+
500+
var model = new CustomModel
501+
{
502+
Id = 1,
503+
Name = "Test"
504+
};
505+
506+
MyController<DbContextController>
507+
.Instance()
508+
.WithData(model)
509+
.WithoutData(default(List<object>))
510+
.Calling(c => c.Get(model.Id))
511+
.ShouldReturn()
512+
.NotFound();
513+
},
514+
"Value cannot be null. (Parameter 'entities')");
513515
}
514516

515517
[Fact]
@@ -581,7 +583,7 @@ public void WithoutDataWithProvidedOnlyPartialDataForDeletionReturnsCorrectResul
581583
.ShouldReturn()
582584
.Ok(ok => ok
583585
.WithModelOfType<List<CustomModel>>()
584-
.Passing(mdls => mdls.Count == 1));
586+
.Passing(model => model.Count == 1));
585587
}
586588

587589
[Fact]

test/MyTested.AspNetCore.Mvc.Http.Test/PluginsTests/HttpTestPluginTest.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
namespace MyTested.AspNetCore.Mvc.Test.PluginsTests
1+
using Microsoft.AspNetCore.Mvc.Controllers;
2+
3+
namespace MyTested.AspNetCore.Mvc.Test.PluginsTests
24
{
35
using System;
4-
using Microsoft.AspNetCore.Mvc.Formatters.Json.Internal;
56
using Microsoft.Extensions.DependencyInjection;
67
using Microsoft.Extensions.Options;
78
using Plugins;
@@ -36,10 +37,7 @@ public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollectionForDefaultRegi
3637

3738
testPlugin.DefaultServiceRegistrationDelegate(serviceCollection);
3839

39-
var methodReturnType = testPlugin.DefaultServiceRegistrationDelegate.Method.ReturnType.Name;
40-
41-
Assert.True(methodReturnType == "Void");
42-
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(JsonResultExecutor));
40+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(IControllerFactory));
4341
}
4442

4543
[Fact]
@@ -50,11 +48,7 @@ public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()
5048

5149
testPlugin.ServiceRegistrationDelegate(serviceCollection);
5250

53-
var methodReturnType = testPlugin.ServiceRegistrationDelegate.Method.ReturnType.Name;
54-
55-
Assert.True(methodReturnType == "Void");
5651
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(IOptions<>));
57-
5852
}
5953
}
6054
}

test/MyTested.AspNetCore.Mvc.Routing.Test/PluginsTests/RoutingTestPluginTest.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace MyTested.AspNetCore.Mvc.Test.PluginsTests
22
{
33
using System;
4-
using Microsoft.AspNetCore.Mvc.Formatters.Json.Internal;
4+
using Internal.Contracts;
5+
using Microsoft.AspNetCore.Mvc.Controllers;
56
using Microsoft.Extensions.DependencyInjection;
6-
using MyTested.AspNetCore.Mvc.Internal.Contracts;
77
using Plugins;
88
using Xunit;
99

@@ -36,10 +36,7 @@ public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollectionForDefaultRegi
3636

3737
testPlugin.DefaultServiceRegistrationDelegate(serviceCollection);
3838

39-
var methodReturnType = testPlugin.DefaultServiceRegistrationDelegate.Method.ReturnType.Name;
40-
41-
Assert.True(methodReturnType == "Void");
42-
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(JsonResultExecutor));
39+
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(IControllerFactory));
4340
}
4441

4542
[Fact]
@@ -50,9 +47,6 @@ public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()
5047

5148
testPlugin.RoutingServiceRegistrationDelegate(serviceCollection);
5249

53-
var methodReturnType = testPlugin.RoutingServiceRegistrationDelegate.Method.ReturnType.Name;
54-
55-
Assert.True(methodReturnType == "Void");
5650
Assert.Contains(serviceCollection, s => s.ServiceType == typeof(IRoutingServices));
5751
}
5852
}

0 commit comments

Comments
 (0)