Skip to content

Commit 6864017

Browse files
Merge pull request #105 from telerik/R3.2019Lite
Merge R3.2019 lite to master
2 parents 0855082 + 8604a13 commit 6864017

11 files changed

Lines changed: 3142 additions & 1446 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
JustMock Lite
22
===
33

4-
[![release](https://img.shields.io/badge/release-R2%20SP1%202019-blue.svg)](https://www.nuget.org/packages/JustMock/)
4+
[![release](https://img.shields.io/badge/release-R3%202019-blue.svg)](https://www.nuget.org/packages/JustMock/)
55
[![nuget](https://img.shields.io/nuget/v/JustMock.svg?label=nuget)](https://www.nuget.org/packages/JustMock/)
66
[![license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/telerik/JustMockLite/blob/master/LICENSE/)
77

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
JustMock Lite
3+
Copyright © 2019 Progress Software Corporation
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
using System;
19+
20+
namespace Telerik.JustMock.DemoLibSigned
21+
{
22+
internal class BaseInternal
23+
{
24+
public const int DefaultValue = 3;
25+
26+
public int i = DefaultValue;
27+
28+
public BaseInternal(int i)
29+
{
30+
this.i = i;
31+
}
32+
}
33+
}

Telerik.JustMock.Tests/ConstructorFixture.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -131,38 +131,6 @@ public class CtorLongArg
131131
public CtorLongArg(long l) { }
132132
}
133133

134-
public class Base
135-
{
136-
public int i;
137-
138-
public Base(int i)
139-
{
140-
this.i = i;
141-
}
142-
}
143-
144-
[TestMethod, TestCategory("Lite"), TestCategory("Constructor")]
145-
public void ShouldUseAutoselectedConstructorMockingBehaviorWithFluentConfig()
146-
{
147-
var proxy = Mock.Create<Base>(fluentConfig =>
148-
{
149-
fluentConfig.Implements<IDisposable>();
150-
});
151-
152-
Assert.Equal(0, proxy.i);
153-
}
154-
155-
[TestMethod, TestCategory("Lite"), TestCategory("Constructor")]
156-
public void ShouldSpecifyConstructorArgumentsWithFluentConfig()
157-
{
158-
var proxy = Mock.Create<Base>(fluentConfig =>
159-
fluentConfig.Implements<IDisposable>()
160-
.CallConstructor(new object[] { 5 })
161-
);
162-
163-
Assert.Equal(5, proxy.i);
164-
}
165-
166134
public class CallsCtor
167135
{
168136
public bool ok;

Telerik.JustMock.Tests/MockFixture.cs

Lines changed: 215 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
JustMock Lite
3-
Copyright © 2010-2015 Progress Software Corporation
3+
Copyright © 2010-2015,2019 Progress Software Corporation
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -2479,10 +2479,220 @@ void Scope.IImplementable2.Do()
24792479
}
24802480
}
24812481
#endif
2482-
}
24832482

2484-
internal abstract class InternalAbstract
2485-
{
2486-
internal abstract string Bar { get; set; }
2483+
internal abstract class InternalAbstract
2484+
{
2485+
internal abstract string Bar { get; set; }
2486+
}
2487+
2488+
#region Category "FluentConfig"
2489+
2490+
public class Base
2491+
{
2492+
public const int DefaultValue = 3;
2493+
2494+
public int i = DefaultValue;
2495+
2496+
public Base(int i)
2497+
{
2498+
this.i = i;
2499+
}
2500+
}
2501+
2502+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2503+
public void ShouldUseAutoselectedConstructorMockingBehaviorWithFluentGenericConfig()
2504+
{
2505+
var proxy = Mock.Create<Base>(fluentConfig => { });
2506+
2507+
Assert.Equal(default(int), proxy.i);
2508+
Assert.Null(proxy as IDisposable);
2509+
}
2510+
2511+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2512+
public void ShouldMockWhenMissingPameterlessConstructorAndRecursiveLooseWithFluentGenericConfig()
2513+
{
2514+
var proxy = Mock.Create<Base>(fluentConfig =>
2515+
fluentConfig.SetBehavior(Behavior.RecursiveLoose)
2516+
);
2517+
2518+
Assert.Equal(default(int), proxy.i);
2519+
Assert.Null(proxy as IDisposable);
2520+
}
2521+
2522+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2523+
public void ShouldMockWhenMissingPameterlessConstructorAndLooseWithFluentGenericConfig()
2524+
{
2525+
var proxy = Mock.Create<Base>(fluentConfig =>
2526+
fluentConfig.SetBehavior(Behavior.Loose)
2527+
);
2528+
2529+
Assert.Equal(default(int), proxy.i);
2530+
Assert.Null(proxy as IDisposable);
2531+
}
2532+
2533+
// Implementation differs for .NETFramework and .NETCore, see DynamicProxyMockFactory.Create method
2534+
#if !NETCORE
2535+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2536+
public void ShouldThrowWhenMissingPameterlessConstructorAndCallOriginalWithFluentGenericConfig()
2537+
{
2538+
Assert.Throws<MockException>(() =>
2539+
Mock.Create<Base>(fluentConfig =>
2540+
fluentConfig.SetBehavior(Behavior.CallOriginal))
2541+
);
2542+
}
2543+
#else
2544+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2545+
public void ShouldMockWhenMissingPameterlessConstructorAndCallOriginalWithFluentGenericConfig()
2546+
{
2547+
var proxy = Mock.Create<Base>(fluentConfig =>
2548+
fluentConfig.SetBehavior(Behavior.CallOriginal)
2549+
);
2550+
2551+
Assert.Equal(default(int), proxy.i);
2552+
Assert.Null(proxy as IDisposable);
2553+
}
2554+
#endif
2555+
2556+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2557+
public void ShouldThrowWhenMockConstructorAndCallConstructorWithFluentGenericConfig()
2558+
{
2559+
Assert.Throws<MockException>(() =>
2560+
Mock.Create<Base>(fluentConfig =>
2561+
fluentConfig.MockConstructor().CallConstructor(new object[] { 5 }))
2562+
);
2563+
}
2564+
2565+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2566+
public void ShouldThrowWhenCallConstructorAndMockConstructorWithFluentGenericConfig()
2567+
{
2568+
Assert.Throws<MockException>(() =>
2569+
Mock.Create<Base>(fluentConfig =>
2570+
fluentConfig.CallConstructor(new object[] { 5 }).MockConstructor())
2571+
);
2572+
}
2573+
2574+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2575+
public void ShouldSpecifyConstructorArgumentsWithFluentGenericConfig()
2576+
{
2577+
var proxy = Mock.Create<Base>(fluentConfig =>
2578+
fluentConfig.CallConstructor(new object[] { 5 })
2579+
);
2580+
2581+
Assert.Equal(5, proxy.i);
2582+
Assert.Null(proxy as IDisposable);
2583+
}
2584+
2585+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2586+
public void ShouldMockConstructorWithFluentGenericConfig()
2587+
{
2588+
var proxy = Mock.Create<Base>(fluentConfig =>
2589+
fluentConfig.MockConstructor()
2590+
);
2591+
2592+
Assert.Equal(default(int), proxy.i);
2593+
Assert.Null(proxy as IDisposable);
2594+
}
2595+
2596+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2597+
public void ShouldImplementInterfaceWithFluentGenericConfig()
2598+
{
2599+
var proxy = Mock.Create<Base>(fluentConfig =>
2600+
fluentConfig.Implements<IDisposable>()
2601+
);
2602+
2603+
Assert.Equal(default(int), proxy.i);
2604+
Assert.NotNull(proxy as IDisposable);
2605+
}
2606+
2607+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2608+
public void ShouldUseAutoselectedConstructorMockingBehaviorWithFluentConfig()
2609+
{
2610+
var proxy = (Base)Mock.Create(typeof(Base), fluentConfig => { });
2611+
2612+
Assert.Equal(default(int), proxy.i);
2613+
}
2614+
2615+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2616+
public void ShouldMockWhenMissingPameterlessConstructorAndRecursiveLooseWithFluentConfig()
2617+
{
2618+
var proxy = (Base)Mock.Create(typeof(Base), fluentConfig =>
2619+
fluentConfig.SetBehavior(Behavior.RecursiveLoose)
2620+
);
2621+
2622+
Assert.Equal(default(int), proxy.i);
2623+
}
2624+
2625+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2626+
public void ShouldMockWhenMissingPameterlessConstructorAndLooseWithFluentConfig()
2627+
{
2628+
var proxy = (Base)Mock.Create(typeof(Base), fluentConfig =>
2629+
fluentConfig.SetBehavior(Behavior.Loose)
2630+
);
2631+
2632+
Assert.Equal(default(int), proxy.i);
2633+
}
2634+
2635+
// Implementation differs for .NETFramework and .NETCore, see DynamicProxyMockFactory.Create method
2636+
#if !NETCORE
2637+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2638+
public void ShouldThrowWhenMissingPameterlessConstructorAndCallOriginalWithFluentConfig()
2639+
{
2640+
Assert.Throws<MockException>(() =>
2641+
Mock.Create(typeof(Base), fluentConfig =>
2642+
fluentConfig.SetBehavior(Behavior.CallOriginal))
2643+
);
2644+
}
2645+
#else
2646+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2647+
public void ShouldMockWhenMissingPameterlessConstructorAndCallOriginalWithFluentConfig()
2648+
{
2649+
var proxy = (Base)Mock.Create(typeof(Base), fluentConfig =>
2650+
fluentConfig.SetBehavior(Behavior.CallOriginal)
2651+
);
2652+
2653+
Assert.Equal(default(int), proxy.i);
2654+
}
2655+
#endif
2656+
2657+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2658+
public void ShouldThrowWhenMockConstructorAndCallConstructorWithFluentConfig()
2659+
{
2660+
Assert.Throws<MockException>(() =>
2661+
Mock.Create(typeof(Base), fluentConfig =>
2662+
fluentConfig.MockConstructor().CallConstructor(new object[] { 5 }))
2663+
);
2664+
}
2665+
2666+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2667+
public void ShouldThrowWhenCallConstructorAndMockConstructorWithFluentConfig()
2668+
{
2669+
Assert.Throws<MockException>(() =>
2670+
Mock.Create(typeof(Base), fluentConfig =>
2671+
fluentConfig.CallConstructor(new object[] { 5 }).MockConstructor())
2672+
);
2673+
}
2674+
2675+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2676+
public void ShouldSpecifyConstructorArgumentsWithFluentConfig()
2677+
{
2678+
var proxy = (Base)Mock.Create(typeof(Base), fluentConfig =>
2679+
fluentConfig.CallConstructor(new object[] { 5 })
2680+
);
2681+
2682+
Assert.Equal(5, proxy.i);
2683+
}
2684+
2685+
[TestMethod, TestCategory("Lite"), TestCategory("Mock"), TestCategory("FluentConfig")]
2686+
public void ShouldMockConstructorWithFluentConfig()
2687+
{
2688+
var proxy = (Base)Mock.Create(typeof(Base), fluentConfig =>
2689+
fluentConfig.MockConstructor()
2690+
);
2691+
2692+
Assert.Equal(default(int), proxy.i);
2693+
}
2694+
2695+
#endregion
24872696
}
2697+
24882698
}

0 commit comments

Comments
 (0)