Skip to content

Commit 5a0f6fb

Browse files
committed
Fixed MemoryCacheEntryDetailsTestBuilder interfaces and added samples (#closes 180)
1 parent 5798b9a commit 5a0f6fb

20 files changed

Lines changed: 102 additions & 115 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ MyMvc
169169
.MemoryCache(cache => cache
170170
.ContainingEntry(entry => entry
171171
.WithKey("CacheEntry")
172-
.WithSlidingExpiration(TimeSpan.FromMinutes(10))))
172+
.WithSlidingExpiration(TimeSpan.FromMinutes(10))
173+
.WithValueOfType<CachedModel>()
174+
.Passing(a => a.Id == 1)))
173175
.AndAlso()
174176
.ShouldReturn()
175177
.View()

samples/MusicStore/MusicStore.Test/Controllers/StoreControllerTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ public void DetailsShouldAlbumDetails()
9393
.MemoryCache(cache => cache
9494
.ContainingEntry(entry => entry
9595
.WithKey("album_1")
96-
.WithSlidingExpiration(TimeSpan.FromMinutes(10))))
96+
.WithSlidingExpiration(TimeSpan.FromMinutes(10))
97+
.WithValueOfType<Album>()
98+
.Passing(a => a.AlbumId == 1)))
9799
.AndAlso()
98100
.ShouldReturn()
99101
.View()

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Contracts/Data/IAndDataProviderEntryDetailsTestBuilder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
/// <summary>
44
/// Used for adding AndAlso() method to the data provider entry details tests.
55
/// </summary>
6-
public interface IAndDataProviderEntryDetailsTestBuilder<TEntry> : IDataProviderEntryDetailsTestBuilder<TEntry>
6+
/// <typeparam name="TValue">Type of data provider entry value.</typeparam>
7+
public interface IAndDataProviderEntryDetailsTestBuilder<TValue> : IDataProviderEntryDetailsTestBuilder<TValue>
78
{
89
/// <summary>
910
/// AndAlso method for better readability when chaining data provider entry details tests.
1011
/// </summary>
11-
/// <returns>The same <see cref="IDataProviderEntryDetailsTestBuilder{TEntry}"/>.</returns>
12-
IDataProviderEntryDetailsTestBuilder<TEntry> AndAlso();
12+
/// <returns>The same <see cref="IDataProviderEntryDetailsTestBuilder{TValue}"/>.</returns>
13+
IDataProviderEntryDetailsTestBuilder<TValue> AndAlso();
1314
}
1415
}

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Contracts/Data/IDataProviderEntryDetailsTestBuilder.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
/// <summary>
66
/// Used for testing data provider entry details.
77
/// </summary>
8-
/// <typeparam name="TEntry">Type of data provider entry value.</typeparam>
9-
public interface IDataProviderEntryDetailsTestBuilder<TEntry>
8+
/// <typeparam name="TValue">Type of data provider entry value.</typeparam>
9+
public interface IDataProviderEntryDetailsTestBuilder<TValue>
1010
{
1111
/// <summary>
1212
/// Tests whether the data provider entry passes the given assertions.
1313
/// </summary>
1414
/// <param name="assertions">Action containing all assertions on the data provider entry.</param>
15-
/// <returns>The same <see cref="IAndDataProviderEntryDetailsTestBuilder{TEntry}"/>.</returns>
16-
IAndDataProviderEntryDetailsTestBuilder<TEntry> Passing(Action<TEntry> assertions);
15+
/// <returns>The same <see cref="IAndDataProviderEntryDetailsTestBuilder{TValue}"/>.</returns>
16+
IAndDataProviderEntryDetailsTestBuilder<TValue> Passing(Action<TValue> assertions);
1717

1818
/// <summary>
1919
/// Tests whether the data provider entry passes the given predicate.
2020
/// </summary>
2121
/// <param name="predicate">Predicate testing the data provider entry.</param>
22-
/// <returns>The same <see cref="IAndDataProviderEntryDetailsTestBuilder{TEntry}"/>.</returns>
23-
IAndDataProviderEntryDetailsTestBuilder<TEntry> Passing(Func<TEntry, bool> predicate);
22+
/// <returns>The same <see cref="IAndDataProviderEntryDetailsTestBuilder{TValue}"/>.</returns>
23+
IAndDataProviderEntryDetailsTestBuilder<TValue> Passing(Func<TValue, bool> predicate);
2424
}
2525
}

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Contracts/Data/IDataProviderEntryTestBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public interface IDataProviderEntryTestBuilder
1515
/// <summary>
1616
/// Tests whether the value of the built data provider entry is of the same type as the provided one.
1717
/// </summary>
18-
/// <typeparam name="TEntry">Type of the data provider entry.</typeparam>
18+
/// <typeparam name="TValue">Type of the data provider entry.</typeparam>
1919
/// <returns>The same <see cref="IAndDataProviderEntryTestBuilder"/>.</returns>
20-
IAndDataProviderEntryDetailsTestBuilder<TEntry> WithValueOfType<TEntry>();
20+
IAndDataProviderEntryDetailsTestBuilder<TValue> WithValueOfType<TValue>();
2121
}
2222
}

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Data/BaseDataProviderTestBuilder.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ protected void ValidateContainingEntryWithKey(string key)
7373
/// <summary>
7474
/// Validates whether the data provider contains entry with the given value.
7575
/// </summary>
76-
/// <typeparam name="TEntry">Type of the value.</typeparam>
76+
/// <typeparam name="TValue">Type of the value.</typeparam>
7777
/// <param name="value">Value to validate.</param>
78-
protected void ValidateContainingEntryWithValue<TEntry>(TEntry value)
78+
protected void ValidateContainingEntryWithValue<TValue>(TValue value)
7979
{
8080
DictionaryValidator.ValidateValue(
8181
this.DataProviderName,
@@ -87,10 +87,10 @@ protected void ValidateContainingEntryWithValue<TEntry>(TEntry value)
8787
/// <summary>
8888
/// Validates whether the data provider contains entry value with the given type.
8989
/// </summary>
90-
/// <typeparam name="TEntry">Type of the value.</typeparam>
91-
protected void ValidateContainingEntryOfType<TEntry>()
90+
/// <typeparam name="TValue">Type of the value.</typeparam>
91+
protected void ValidateContainingEntryOfType<TValue>()
9292
{
93-
DictionaryValidator.ValidateValueOfType<TEntry>(
93+
DictionaryValidator.ValidateValueOfType<TValue>(
9494
this.DataProviderName,
9595
this.DataProvider,
9696
this.ThrowNewDataProviderAssertionException);
@@ -99,11 +99,11 @@ protected void ValidateContainingEntryOfType<TEntry>()
9999
/// <summary>
100100
/// Validates whether the data provider contains entry value with the given type and corresponding key.
101101
/// </summary>
102-
/// <typeparam name="TEntry">Type of the value.</typeparam>
102+
/// <typeparam name="TValue">Type of the value.</typeparam>
103103
/// <param name="key">Key to validate.</param>
104-
protected void ValidateContainingEntryOfType<TEntry>(string key)
104+
protected void ValidateContainingEntryOfType<TValue>(string key)
105105
{
106-
DictionaryValidator.ValidateStringKeyAndValueOfType<TEntry>(
106+
DictionaryValidator.ValidateStringKeyAndValueOfType<TValue>(
107107
this.DataProviderName,
108108
this.DataProvider,
109109
key,

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Data/BaseDataProviderWithStringKeyTestBuilder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ public TDataProviderTestBuilder ContainingEntryWithKey(string key)
3838
}
3939

4040
/// <inheritdoc />
41-
public TDataProviderTestBuilder ContainingEntryWithValue<TEntry>(TEntry value)
41+
public TDataProviderTestBuilder ContainingEntryWithValue<TValue>(TValue value)
4242
{
4343
this.ValidateContainingEntryWithValue(value);
4444
return this.DataProviderTestBuilder;
4545
}
4646

4747
/// <inheritdoc />
48-
public TDataProviderTestBuilder ContainingEntryOfType<TEntry>()
48+
public TDataProviderTestBuilder ContainingEntryOfType<TValue>()
4949
{
50-
this.ValidateContainingEntryOfType<TEntry>();
50+
this.ValidateContainingEntryOfType<TValue>();
5151
return this.DataProviderTestBuilder;
5252
}
5353

5454
/// <inheritdoc />
55-
public TDataProviderTestBuilder ContainingEntryOfType<TEntry>(string key)
55+
public TDataProviderTestBuilder ContainingEntryOfType<TValue>(string key)
5656
{
57-
this.ValidateContainingEntryOfType<TEntry>(key);
57+
this.ValidateContainingEntryOfType<TValue>(key);
5858
return this.DataProviderTestBuilder;
5959
}
6060

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Data/DataProviderEntryDetailsTestBuilder.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
/// <summary>
99
/// Used for testing data provider entry details.
1010
/// </summary>
11-
/// <typeparam name="TEntry">Type of data provider entry value.</typeparam>
12-
public class DataProviderEntryDetailsTestBuilder<TEntry> : BaseTestBuilderWithComponent, IAndDataProviderEntryDetailsTestBuilder<TEntry>
11+
/// <typeparam name="TValue">Type of data provider entry value.</typeparam>
12+
public class DataProviderEntryDetailsTestBuilder<TValue> : BaseTestBuilderWithComponent, IAndDataProviderEntryDetailsTestBuilder<TValue>
1313
{
1414
private readonly DataProviderEntryTestBuilder dataProviderEntryTestBuilder;
1515

1616
/// <summary>
17-
/// Initializes a new instance of the <see cref="DataProviderEntryDetailsTestBuilder{TEntry}"/> class.
17+
/// Initializes a new instance of the <see cref="DataProviderEntryDetailsTestBuilder{TValue}"/> class.
1818
/// </summary>
1919
/// <param name="dataProviderEntryTestBuilder">Test builder of <see cref="DataProviderEntryTestBuilder"/> type.</param>
2020
public DataProviderEntryDetailsTestBuilder(DataProviderEntryTestBuilder dataProviderEntryTestBuilder)
@@ -25,23 +25,23 @@ public DataProviderEntryDetailsTestBuilder(DataProviderEntryTestBuilder dataProv
2525
}
2626

2727
/// <inheritdoc />
28-
public IAndDataProviderEntryDetailsTestBuilder<TEntry> Passing(Action<TEntry> assertions)
28+
public IAndDataProviderEntryDetailsTestBuilder<TValue> Passing(Action<TValue> assertions)
2929
{
3030
this.dataProviderEntryTestBuilder
3131
.GetDataProviderEntryValidations()
32-
.Add(actual => assertions((TEntry)actual));
32+
.Add(actual => assertions((TValue)actual));
3333

3434
return this;
3535
}
3636

3737
/// <inheritdoc />
38-
public IAndDataProviderEntryDetailsTestBuilder<TEntry> Passing(Func<TEntry, bool> predicate)
38+
public IAndDataProviderEntryDetailsTestBuilder<TValue> Passing(Func<TValue, bool> predicate)
3939
{
4040
this.dataProviderEntryTestBuilder
4141
.GetDataProviderEntryValidations()
4242
.Add(actual =>
4343
{
44-
if (!predicate((TEntry)actual))
44+
if (!predicate((TValue)actual))
4545
{
4646
var entryKey = this.dataProviderEntryTestBuilder.GetDataProviderEntryKey();
4747

@@ -55,6 +55,6 @@ public IAndDataProviderEntryDetailsTestBuilder<TEntry> Passing(Func<TEntry, bool
5555
}
5656

5757
/// <inheritdoc />
58-
public IDataProviderEntryDetailsTestBuilder<TEntry> AndAlso() => this;
58+
public IDataProviderEntryDetailsTestBuilder<TValue> AndAlso() => this;
5959
}
6060
}

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Data/DataProviderEntryTestBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public IAndDataProviderEntryTestBuilder WithValue(object value)
6161
}
6262

6363
/// <inheritdoc />
64-
public IAndDataProviderEntryDetailsTestBuilder<TEntry> WithValueOfType<TEntry>()
64+
public IAndDataProviderEntryDetailsTestBuilder<TValue> WithValueOfType<TValue>()
6565
{
6666
this.validations.Add((actual) =>
6767
{
68-
var expectedType = typeof(TEntry);
68+
var expectedType = typeof(TValue);
6969
var actualType = actual.GetType();
7070

7171
if (Reflection.AreDifferentTypes(expectedType, actualType))
@@ -76,7 +76,7 @@ public IAndDataProviderEntryDetailsTestBuilder<TEntry> WithValueOfType<TEntry>()
7676
}
7777
});
7878

79-
return new DataProviderEntryDetailsTestBuilder<TEntry>(this);
79+
return new DataProviderEntryDetailsTestBuilder<TValue>(this);
8080
}
8181

8282
/// <inheritdoc />

src/MyTested.AspNetCore.Mvc.Caching/Builders/Contracts/Data/IAndMemoryCacheEntryDetailsTestBuilder.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)