This repository was archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAbstractStrategyTest.cs
More file actions
142 lines (114 loc) · 4.94 KB
/
AbstractStrategyTest.cs
File metadata and controls
142 lines (114 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//-------------------------------------------------------------------------------
// <copyright file="AbstractStrategyTest.cs" company="Appccelerate">
// Copyright (c) 2008-2015
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
//-------------------------------------------------------------------------------
namespace Appccelerate.Bootstrapper
{
using System;
using Appccelerate.Bootstrapper.Execution;
using Appccelerate.Bootstrapper.Extension;
using Appccelerate.Bootstrapper.Reporting;
using Appccelerate.Bootstrapper.Syntax;
using FakeItEasy;
using FluentAssertions;
using Xunit;
public class AbstractStrategyTest
{
private readonly TestableAbstractStrategy testee;
private readonly ISyntaxBuilder<IExtension> runSyntaxBuilder;
private readonly ISyntaxBuilder<IExtension> shutdownSyntaxBuilder;
public AbstractStrategyTest()
{
this.runSyntaxBuilder = A.Fake<ISyntaxBuilder<IExtension>>();
this.shutdownSyntaxBuilder = A.Fake<ISyntaxBuilder<IExtension>>();
this.testee = new TestableAbstractStrategy(this.runSyntaxBuilder, this.shutdownSyntaxBuilder);
}
[Fact]
public void BuildRunSyntax_WhenCalledMultipleTimes_ShouldThrowException()
{
this.testee.BuildRunSyntax();
this.testee.Invoking(x => x.BuildRunSyntax()).Should().Throw<InvalidOperationException>();
}
[Fact]
public void BuildRunSyntax_ShouldReturnDefinedRunSyntax()
{
var syntax = this.testee.BuildRunSyntax();
syntax.Equals(this.runSyntaxBuilder).Should().BeTrue();
this.testee.RunSyntaxBuilder.Equals(this.runSyntaxBuilder).Should().BeTrue();
}
[Fact]
public void BuildShutdownSyntax_WhenCalledMultipleTimes_ShouldThrowException()
{
this.testee.BuildShutdownSyntax();
this.testee.Invoking(x => x.BuildShutdownSyntax()).Should().Throw<InvalidOperationException>();
}
[Fact]
public void BuildShutdownSyntax_ShouldReturnDefinedRunSyntax()
{
var syntax = this.testee.BuildShutdownSyntax();
syntax.Equals(this.shutdownSyntaxBuilder).Should().BeTrue();
this.testee.ShutdownSyntaxBuilder.Equals(this.shutdownSyntaxBuilder).Should().BeTrue();
}
[Fact]
public void CreateRunExecutor_ShouldCreateSynchronousExecutor()
{
var runExecutor = this.testee.CreateRunExecutor();
runExecutor.Should().BeOfType<SynchronousExecutor<IExtension>>();
}
[Fact]
public void CreateShutdownExecutor_ShouldCreateSynchronousReverseExecutor()
{
var runExecutor = this.testee.CreateShutdownExecutor();
runExecutor.Should().BeOfType<SynchronousReverseExecutor<IExtension>>();
}
[Fact]
public void CreateExtensionResolver_ShouldCreateNullExtensionResolver()
{
var extensionResolver = this.testee.CreateExtensionResolver();
extensionResolver.Should().BeOfType<NullExtensionResolver<IExtension>>();
}
[Fact]
public void CreateReportingContext_ShouldCreateReportingContext()
{
var reportingContext = this.testee.CreateReportingContext();
reportingContext.Should().BeOfType<ReportingContext>();
}
[Fact]
public void Dispose_MultipleTimes_ShouldNotThrow()
{
this.testee.Dispose();
this.testee.Invoking(t => t.Dispose()).Should().NotThrow();
}
private class TestableAbstractStrategy : AbstractStrategy<IExtension>
{
public TestableAbstractStrategy(ISyntaxBuilder<IExtension> runSyntaxBuilder,
ISyntaxBuilder<IExtension> shutdownSyntaxBuilder)
: base(runSyntaxBuilder, shutdownSyntaxBuilder)
{
}
public ISyntaxBuilder<IExtension> RunSyntaxBuilder { get; private set; }
public ISyntaxBuilder<IExtension> ShutdownSyntaxBuilder { get; private set; }
protected override void DefineRunSyntax(ISyntaxBuilder<IExtension> builder)
{
this.RunSyntaxBuilder = builder;
}
protected override void DefineShutdownSyntax(ISyntaxBuilder<IExtension> builder)
{
this.ShutdownSyntaxBuilder = builder;
}
}
}
}