Skip to content

Commit dcdd122

Browse files
committed
MSpec fixes for auto-assign references
1 parent 6ea9868 commit dcdd122

10 files changed

Lines changed: 139 additions & 51 deletions

File tree

‎src/IncFramework.sln‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ Global
178178
{5D9E0EB3-4339-42DA-B5C2-9D4FF667D7D9} = {540D8C0B-630F-48A8-875B-8CFA62F498E2}
179179
EndGlobalSection
180180
GlobalSection(ExtensibilityGlobals) = postSolution
181-
BuildVersion_UpdateAssemblyVersion = False
182-
BuildVersion_UpdateFileVersion = False
183-
BuildVersion_BuildAction = ReBuild
184-
BuildVersion_IncrementBeforeBuild = True
185-
BuildVersion_DetectChanges = True
186-
BuildVersion_BuildVersioningStyle = None.None.None.None
187181
SolutionGuid = {834D889F-F4B3-4006-83EC-584703FCCDA2}
182+
BuildVersion_BuildVersioningStyle = None.None.None.None
183+
BuildVersion_DetectChanges = True
184+
BuildVersion_IncrementBeforeBuild = True
185+
BuildVersion_BuildAction = ReBuild
186+
BuildVersion_UpdateFileVersion = False
187+
BuildVersion_UpdateAssemblyVersion = False
188188
EndGlobalSection
189189
GlobalSection(NDepend) = preSolution
190190
Project = ".\IncFramework.ndproj"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Runtime.Serialization;
2+
using Incoding.Core.Quality;
3+
using Newtonsoft.Json;
4+
5+
namespace Incoding.Core.CQRS.Core
6+
{
7+
public abstract class CommandBase<T> : CommandBase
8+
{
9+
[IgnoreCompare("Design fixed")]
10+
[JsonIgnore]
11+
[IgnoreDataMember]
12+
public new virtual T Result { get; protected set; }
13+
14+
protected sealed override void Execute()
15+
{
16+
Result = ExecuteResult();
17+
}
18+
19+
protected abstract T ExecuteResult();
20+
}
21+
}

‎src/Incoding.Core/CQRS/DispatcherExtensions.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ public static TResult Query<TResult>(this IDispatcher dispatcher, QueryBase<TRes
3838
return dispatcher.Query(message, setting);
3939
}
4040

41+
public static T Push<T>(this IDispatcher dispatcher, CommandBase<T> message)
42+
{
43+
dispatcher.Push(message, (MessageExecuteSetting)null);
44+
return message.Result;
45+
}
46+
47+
public static T Push<T>(this IDispatcher dispatcher, CommandBase message) where T : class
48+
{
49+
dispatcher.Push(message);
50+
return message.Result as T;
51+
}
52+
4153
#endregion
4254
}
4355
}

‎src/Incoding.UnitTests.MSpec/Data Base/PersistenceSpecification.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,14 @@ public void VerifyMappingAndSchema(Action<PersistenceSpecification<TEntity>> con
117117
object invent;
118118
if (missing.PropertyType.IsImplement<IEntity>())
119119
{
120-
invent = ((IQueryable)Repository.GetType().GetMethod("Query").MakeGenericMethod(missing.PropertyType).Invoke(Repository, new object[] { null, null, null, null }));
120+
var queryable = ((IQueryable)Repository.GetType().GetMethod("Query").MakeGenericMethod(missing.PropertyType).Invoke(Repository, new object[] { null, null, null, null }));
121+
122+
var firstOrDefaultMethod = typeof(System.Linq.Queryable).GetMethods(BindingFlags.Static | BindingFlags.Public)
123+
.FirstOrDefault(m => m.Name == "FirstOrDefault" && m.GetParameters().Count() == 1);
124+
125+
126+
firstOrDefaultMethod = firstOrDefaultMethod.MakeGenericMethod(missing.PropertyType);
127+
invent = firstOrDefaultMethod.Invoke(null, new object[] {queryable});
121128
if (invent == null)
122129
throw new SpecificationException("No elements at database for type '{0}'".F(missing.PropertyType.Name));
123130
}

‎src/Incoding.UnitTests.MSpec/Incoding.UnitTests.MSpec.csproj‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
<PackageId>Incoding.UnitTests.MSpec</PackageId>
1919
<AssemblyName>Incoding.UnitTests.MSpec</AssemblyName>
2020
<RootNamespace>Incoding.UnitTests.MSpec</RootNamespace>
21-
<Version>1.0.2</Version>
22-
<AssemblyVersion>1.0.2.0</AssemblyVersion>
23-
<FileVersion>1.0.2.0</FileVersion>
21+
<Version>1.0.4</Version>
22+
<AssemblyVersion>1.0.4.0</AssemblyVersion>
23+
<FileVersion>1.0.4.0</FileVersion>
2424
</PropertyGroup>
2525

2626
<ItemGroup>

‎src/Incoding.UnitTests.MSpec/Mock Wapper/MockMessage.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,13 @@ public void ShouldBeIsResult(Action<TResult> verifyResult)
301301
return Stub(message => message.repository.StubGetById(id, res));
302302
}
303303

304-
public MockMessage<TMessage, TResult> StubSave<TEntity>(TEntity res, object id) where TEntity : class, IEntity, new()
304+
public MockMessage<TMessage, TResult> StubSave<TEntity>(TEntity res, object id = null) where TEntity : class, IEntity, new()
305305
{
306306
Action<TEntity> verify = entity =>
307307
{
308308
entity.ShouldEqualWeak(res, null);
309-
entity.SetValue("Id", id);
309+
if(id != null)
310+
entity.SetValue("Id", id);
310311
};
311312
return Stub(message => message.repository.Setup(r => r.Save(Pleasure.MockIt.Is<TEntity>(verify))));
312313
}

‎src/Incoding.UnitTestsCore/Block/Scheduler Factory/When_change_delay_to_schedule_to_success.cs‎

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Incoding.Core.Block.Scheduler.Command;
22
using Incoding.Core.Block.Scheduler.Persistence;
33
using Incoding.Core.Block.Scheduler.Query;
4+
using Incoding.Core.Extensions;
45

56
namespace Incoding.UnitTest
67
{
@@ -17,37 +18,68 @@ namespace Incoding.UnitTest
1718
[Subject(typeof(ChangeSchedulerStatusCommand))]
1819
public class When_change_delay_to_schedule_to_success
1920
{
20-
Establish establish = () =>
21+
private Establish establish = () =>
2122
{
2223
var command = Pleasure.Generator.Invent<ChangeSchedulerStatusCommand>(dsl => dsl.Tuning(s => s.Status, DelayOfStatus.Success));
2324

2425
var instance = Pleasure.Generator.Invent<ChangeSchedulerStatusCommand>();
2526
DateTime? nextDt = Pleasure.Generator.DateTime();
2627
lastStartOn = Pleasure.Generator.DateTime();
28+
recurrency = Pleasure.Generator.Invent<GetRecurrencyDateQuery>(dsl => dsl.Tuning(s => s.NowDate, lastStartOn)
29+
.Tuning(r => r.StartDate, lastStartOn));
2730
delay = Pleasure.MockStrict<DelayToScheduler>(mock =>
2831
{
2932
mock.SetupGet(r => r.StartsOn).Returns(lastStartOn);
3033
mock.SetupGet(r => r.Priority).Returns(Pleasure.Generator.PositiveNumber());
3134
mock.SetupSet(r => r.Status = command.Status);
3235
mock.SetupSet(r => r.Description = command.Description);
3336
mock.SetupGet(r => r.Recurrence).Returns(recurrency);
37+
mock.SetupGet(r => r.Command).Returns(instance.ToJsonString());
38+
mock.SetupGet(r => r.Type)
39+
.Returns(typeof(ChangeSchedulerStatusCommand).AssemblyQualifiedName);
3440
mock.SetupGet(r => r.UID).Returns(Guid.NewGuid().ToString);
3541
});
3642

37-
recurrency = Pleasure.Generator.Invent<GetRecurrencyDateQuery>(dsl => dsl.Tuning(s => s.NowDate, lastStartOn));
3843

3944
Action<ICompareFactoryDsl<ScheduleCommand, ScheduleCommand>> compare
4045
= dsl => dsl.ForwardToAction(r => r.Recurrency, schedulerCommand => schedulerCommand.Recurrency.ShouldEqualWeak(recurrency,
4146
factoryDsl => factoryDsl.ForwardToValue(r => r.NowDate, null)
4247
.ForwardToValue(r => r.RepeatCount, recurrency.RepeatCount - 1)
4348
.ForwardToValue(r => r.StartDate, lastStartOn)));
49+
var newRecurrency = new GetRecurrencyDateQuery
50+
{
51+
EndDate = recurrency.EndDate,
52+
RepeatCount = recurrency.RepeatCount - 1,
53+
RepeatDays = recurrency.RepeatDays,
54+
RepeatInterval = recurrency.RepeatInterval,
55+
StartDate = lastStartOn,
56+
Type = recurrency.Type,
57+
NowDate = lastStartOn
58+
};
59+
var lastRecurrency = new GetRecurrencyDateQuery
60+
{
61+
EndDate = recurrency.EndDate,
62+
RepeatCount = recurrency.RepeatCount - 1,
63+
RepeatDays = recurrency.RepeatDays,
64+
RepeatInterval = recurrency.RepeatInterval,
65+
StartDate = nextDt,
66+
Type = recurrency.Type,
67+
NowDate = lastStartOn
68+
};
4469
mockCommand = MockCommand<ChangeSchedulerStatusCommand>
45-
.When(command)
46-
.StubGetById(command.Id, delay.Object)
47-
.StubQuery(recurrency, nextDt)
48-
.StubPush(dsl => dsl.Tuning(r => r.UID, delay.Object.UID)
49-
.Tuning(r => r.Command, instance)
50-
.Tuning(r => r.Priority, delay.Object.Priority), compare);
70+
.When(command)
71+
.StubGetById(command.Id, delay.Object)
72+
.StubQuery(newRecurrency, nextDt)
73+
.StubPush(new ScheduleCommand(delay.Object)
74+
{
75+
76+
UID = delay.Object.UID,
77+
Priority = delay.Object.Priority,
78+
Recurrency = lastRecurrency
79+
});
80+
//.StubPush(dsl => dsl.Tuning(r => r.UID, delay.Object.UID)
81+
// .Tuning(r => r.Command, instance)
82+
// .Tuning(r => r.Priority, delay.Object.Priority), compare);
5183
};
5284

5385
Because of = () => mockCommand.Execute();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using FluentValidation;
5+
using Incoding.Core.CQRS;
6+
using Incoding.Core.CQRS.Core;
7+
8+
namespace Incoding.WebTest.Operations
9+
{
10+
public class AddItemCommand : CommandBase
11+
{
12+
public string OriginalValue { get; set; }
13+
public List<Guid> ItemId { get; set; }
14+
15+
public class Validator : AbstractValidator<AddItemCommand>
16+
{
17+
public Validator()
18+
{
19+
RuleFor(r => r.OriginalValue).NotEmpty().Must(r =>
20+
{
21+
int val;
22+
return r != null && int.TryParse(r, out val) && val > 15;
23+
}).WithMessage("Value must be greater than 15");
24+
}
25+
}
26+
27+
public class TestGenericCommand : CommandBase<DateTime>
28+
{
29+
protected override DateTime ExecuteResult()
30+
{
31+
//do some stuff, save to database
32+
return DateTime.UtcNow;
33+
}
34+
}
35+
36+
protected override void Execute()
37+
{
38+
var dateTime = Dispatcher.Push(new TestGenericCommand());
39+
Debug.WriteLine(dateTime);
40+
Repository.Save(new ItemEntity()
41+
{
42+
Name = OriginalValue
43+
});
44+
}
45+
}
46+
}

‎src/Incoding.WebTest/Operations/GetItemsQuery.cs‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,11 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using FluentValidation;
43
using Incoding.Core.Block.Caching;
54
using Incoding.Core.Block.Caching.Core;
65
using Incoding.Core.CQRS.Core;
76

87
namespace Incoding.WebTest.Operations
98
{
10-
public class AddItemCommand : CommandBase
11-
{
12-
public string OriginalValue { get; set; }
13-
public List<int> ItemId { get; set; }
14-
15-
public class Validator : AbstractValidator<AddItemCommand>
16-
{
17-
public Validator()
18-
{
19-
RuleFor(r => r.OriginalValue).NotEmpty().Must(r =>
20-
{
21-
int val;
22-
return r != null && int.TryParse(r, out val) && val > 15;
23-
}).WithMessage("Value must be greater than 15");
24-
}
25-
}
26-
27-
protected override void Execute()
28-
{
29-
Repository.Save(new ItemEntity()
30-
{
31-
Name = OriginalValue
32-
});
33-
}
34-
}
35-
369
public class ClearItemCacheCommand : CommandBase
3710
{
3811
protected override void Execute()

‎src/Incoding.WebTest/Views/Item/AddItem.cshtml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
//control.Attr(new RouteValueDictionary {{"multiple", "multiple"}, { "data-plugin-multiselect", "data-plugin-multiselect" } });
1515
})
1616
@Html.ForGroup(r => r.OriginalValue).TextBox(control =>
17-
{
18-
control.Label.Name = "Value:";
19-
})
20-
@Html.ForGroup(r => r.OriginalValue).TextBox(control =>
2117
{
2218
control.Label.Name = "Value:";
2319
control.NestedValidationWithControl = true;

0 commit comments

Comments
 (0)