From 8772a49d4565a03d8455685f5633ffed80bb2cc9 Mon Sep 17 00:00:00 2001 From: Matthew Kubicki Date: Tue, 11 Oct 2016 22:18:49 +0100 Subject: [PATCH] Fixes #278. Only fixes some of the issue though. Also adds new VB test assembly, hopefully in a way people will be happy with (#291) --- Moq.VisualBasicTests/IssueReports.vb | 29 +++++ .../Moq.VisualBasicTests.vbproj | 123 ++++++++++++++++++ .../My Project/Application.Designer.vb | 13 ++ .../My Project/Application.myapp | 10 ++ .../My Project/AssemblyInfo.vb | 35 +++++ .../My Project/Resources.Designer.vb | 63 +++++++++ .../My Project/Resources.resx | 117 +++++++++++++++++ .../My Project/Settings.Designer.vb | 73 +++++++++++ .../My Project/Settings.settings | 7 + Moq.VisualBasicTests/project.json | 13 ++ Moq.sln | 10 ++ Source/Interceptor.cs | 13 +- UnitTests/MockedEventsFixture.cs | 3 +- 13 files changed, 503 insertions(+), 6 deletions(-) create mode 100644 Moq.VisualBasicTests/IssueReports.vb create mode 100644 Moq.VisualBasicTests/Moq.VisualBasicTests.vbproj create mode 100644 Moq.VisualBasicTests/My Project/Application.Designer.vb create mode 100644 Moq.VisualBasicTests/My Project/Application.myapp create mode 100644 Moq.VisualBasicTests/My Project/AssemblyInfo.vb create mode 100644 Moq.VisualBasicTests/My Project/Resources.Designer.vb create mode 100644 Moq.VisualBasicTests/My Project/Resources.resx create mode 100644 Moq.VisualBasicTests/My Project/Settings.Designer.vb create mode 100644 Moq.VisualBasicTests/My Project/Settings.settings create mode 100644 Moq.VisualBasicTests/project.json diff --git a/Moq.VisualBasicTests/IssueReports.vb b/Moq.VisualBasicTests/IssueReports.vb new file mode 100644 index 000000000..a520e286c --- /dev/null +++ b/Moq.VisualBasicTests/IssueReports.vb @@ -0,0 +1,29 @@ +Imports Moq +Imports Xunit + + + +Public Class IssueReports + + Public Class Issue278 + + + Public Sub SetupsForPropertiesWithMultipleArgsDoNotOverwriteEachOther() + Dim mock As New Mock(Of ISimpleInterface)() + + mock.Setup(Function(m) m.PropertyWithMultipleArgs(1, 1)).Returns(1) + mock.Setup(Function(m) m.PropertyWithMultipleArgs(1, 2)).Returns(2) + + Assert.Equal(1, mock.Object.PropertyWithMultipleArgs(1, 1)) + Assert.Equal(2, mock.Object.PropertyWithMultipleArgs(1, 2)) + + End Sub + + Public Interface ISimpleInterface + + ReadOnly Property PropertyWithMultipleArgs(setting As Integer, setting2 As Integer) As Integer + + End Interface + End Class + +End Class diff --git a/Moq.VisualBasicTests/Moq.VisualBasicTests.vbproj b/Moq.VisualBasicTests/Moq.VisualBasicTests.vbproj new file mode 100644 index 000000000..74987e9bc --- /dev/null +++ b/Moq.VisualBasicTests/Moq.VisualBasicTests.vbproj @@ -0,0 +1,123 @@ + + + + + Debug + AnyCPU + {95F2E2B2-2E06-4AC7-A86F-9B1B6369D4AD} + Library + Moq.VisualBasicTests + Moq.VisualBasicTests + 512 + Windows + v4.5 + true + + + true + full + true + true + bin\Debug\ + Moq.VisualBasicTests.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + pdbonly + false + true + true + bin\Release\ + Moq.VisualBasicTests.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + On + + + Binary + + + On + + + On + + + + {1C91AC30-5977-4BE5-BA67-8EB186C03514} + Moq + + + False + ..\..\..\..\..\..\..\AssembliesTPS\nunit.framework.dll + + + + + + + + + + + + + + + + + + + + + + + + + True + Application.myapp + + + True + True + Resources.resx + + + True + Settings.settings + True + + + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + Designer + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + SettingsSingleFileGenerator + My + Settings.Designer.vb + + + + + + + + + \ No newline at end of file diff --git a/Moq.VisualBasicTests/My Project/Application.Designer.vb b/Moq.VisualBasicTests/My Project/Application.Designer.vb new file mode 100644 index 000000000..88dd01c78 --- /dev/null +++ b/Moq.VisualBasicTests/My Project/Application.Designer.vb @@ -0,0 +1,13 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + diff --git a/Moq.VisualBasicTests/My Project/Application.myapp b/Moq.VisualBasicTests/My Project/Application.myapp new file mode 100644 index 000000000..758895def --- /dev/null +++ b/Moq.VisualBasicTests/My Project/Application.myapp @@ -0,0 +1,10 @@ + + + false + false + 0 + true + 0 + 1 + true + diff --git a/Moq.VisualBasicTests/My Project/AssemblyInfo.vb b/Moq.VisualBasicTests/My Project/AssemblyInfo.vb new file mode 100644 index 000000000..93fb40207 --- /dev/null +++ b/Moq.VisualBasicTests/My Project/AssemblyInfo.vb @@ -0,0 +1,35 @@ +Imports System +Imports System.Reflection +Imports System.Runtime.InteropServices + +' General Information about an assembly is controlled through the following +' set of attributes. Change these attribute values to modify the information +' associated with an assembly. + +' Review the values of the assembly attributes + + + + + + + + + + +'The following GUID is for the ID of the typelib if this project is exposed to COM + + +' Version information for an assembly consists of the following four values: +' +' Major Version +' Minor Version +' Build Number +' Revision +' +' You can specify all the values or you can default the Build and Revision Numbers +' by using the '*' as shown below: +' + + + diff --git a/Moq.VisualBasicTests/My Project/Resources.Designer.vb b/Moq.VisualBasicTests/My Project/Resources.Designer.vb new file mode 100644 index 000000000..66fb2066e --- /dev/null +++ b/Moq.VisualBasicTests/My Project/Resources.Designer.vb @@ -0,0 +1,63 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + +Imports System + +Namespace My.Resources + + 'This class was auto-generated by the StronglyTypedResourceBuilder + 'class via a tool like ResGen or Visual Studio. + 'To add or remove a member, edit your .ResX file then rerun ResGen + 'with the /str option, or rebuild your VS project. + ''' + ''' A strongly-typed resource class, for looking up localized strings, etc. + ''' + _ + Friend Module Resources + + Private resourceMan As Global.System.Resources.ResourceManager + + Private resourceCulture As Global.System.Globalization.CultureInfo + + ''' + ''' Returns the cached ResourceManager instance used by this class. + ''' + _ + Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager + Get + If Object.ReferenceEquals(resourceMan, Nothing) Then + Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Moq.VisualBasicTests.Resources", GetType(Resources).Assembly) + resourceMan = temp + End If + Return resourceMan + End Get + End Property + + ''' + ''' Overrides the current thread's CurrentUICulture property for all + ''' resource lookups using this strongly typed resource class. + ''' + _ + Friend Property Culture() As Global.System.Globalization.CultureInfo + Get + Return resourceCulture + End Get + Set + resourceCulture = value + End Set + End Property + End Module +End Namespace diff --git a/Moq.VisualBasicTests/My Project/Resources.resx b/Moq.VisualBasicTests/My Project/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/Moq.VisualBasicTests/My Project/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Moq.VisualBasicTests/My Project/Settings.Designer.vb b/Moq.VisualBasicTests/My Project/Settings.Designer.vb new file mode 100644 index 000000000..ad991681d --- /dev/null +++ b/Moq.VisualBasicTests/My Project/Settings.Designer.vb @@ -0,0 +1,73 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My + + _ + Partial Friend NotInheritable Class MySettings + Inherits Global.System.Configuration.ApplicationSettingsBase + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) + +#Region "My.Settings Auto-Save Functionality" +#If _MyType = "WindowsForms" Then + Private Shared addedHandler As Boolean + + Private Shared addedHandlerLockObject As New Object + + _ + Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub +#End If +#End Region + + Public Shared ReadOnly Property [Default]() As MySettings + Get + +#If _MyType = "WindowsForms" Then + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If +#End If + Return defaultInstance + End Get + End Property + End Class +End Namespace + +Namespace My + + _ + Friend Module MySettingsProperty + + _ + Friend ReadOnly Property Settings() As Global.Moq.VisualBasicTests.My.MySettings + Get + Return Global.Moq.VisualBasicTests.My.MySettings.Default + End Get + End Property + End Module +End Namespace diff --git a/Moq.VisualBasicTests/My Project/Settings.settings b/Moq.VisualBasicTests/My Project/Settings.settings new file mode 100644 index 000000000..85b890b3c --- /dev/null +++ b/Moq.VisualBasicTests/My Project/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Moq.VisualBasicTests/project.json b/Moq.VisualBasicTests/project.json new file mode 100644 index 000000000..1f91f2a97 --- /dev/null +++ b/Moq.VisualBasicTests/project.json @@ -0,0 +1,13 @@ +{ + "dependencies": { + "Castle.Core": "3.3.3", + "xunit": "2.1.0", + "xunit.runner.visualstudio": "2.1.0" + }, + "frameworks": { + "net45": {} + }, + "runtimes": { + "win": {} + } +} \ No newline at end of file diff --git a/Moq.sln b/Moq.sln index 9217dfed3..f38be337b 100644 --- a/Moq.sln +++ b/Moq.sln @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq", "Source\Moq.csproj", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Tests", "UnitTests\Moq.Tests.csproj", "{81BBC911-4916-4E10-A955-752AE47CB2B9}" EndProject +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Moq.VisualBasicTests", "Moq.VisualBasicTests\Moq.VisualBasicTests.vbproj", "{95F2E2B2-2E06-4AC7-A86F-9B1B6369D4AD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -37,6 +39,14 @@ Global {81BBC911-4916-4E10-A955-752AE47CB2B9}.Release|Any CPU.ActiveCfg = Release|Any CPU {81BBC911-4916-4E10-A955-752AE47CB2B9}.Release|Any CPU.Build.0 = Release|Any CPU {81BBC911-4916-4E10-A955-752AE47CB2B9}.Release|x86.ActiveCfg = Release|Any CPU + {95F2E2B2-2E06-4AC7-A86F-9B1B6369D4AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {95F2E2B2-2E06-4AC7-A86F-9B1B6369D4AD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {95F2E2B2-2E06-4AC7-A86F-9B1B6369D4AD}.Debug|x86.ActiveCfg = Debug|Any CPU + {95F2E2B2-2E06-4AC7-A86F-9B1B6369D4AD}.Debug|x86.Build.0 = Debug|Any CPU + {95F2E2B2-2E06-4AC7-A86F-9B1B6369D4AD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {95F2E2B2-2E06-4AC7-A86F-9B1B6369D4AD}.Release|Any CPU.Build.0 = Release|Any CPU + {95F2E2B2-2E06-4AC7-A86F-9B1B6369D4AD}.Release|x86.ActiveCfg = Release|Any CPU + {95F2E2B2-2E06-4AC7-A86F-9B1B6369D4AD}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Source/Interceptor.cs b/Source/Interceptor.cs index c662798bb..d5c8f460c 100644 --- a/Source/Interceptor.cs +++ b/Source/Interceptor.cs @@ -169,12 +169,17 @@ public override bool Equals(object obj) } var eq = key.fixedString == this.fixedString && key.values.Count == this.values.Count; + if(!eq) + { + return false; + } - var index = 0; - while (eq && index < this.values.Count) + for(int index=0; index < values.Count; index++) { - eq |= this.values[index] == key.values[index]; - index++; + if (this.values[index] != key.values[index]) + { + return false; + } } return eq; diff --git a/UnitTests/MockedEventsFixture.cs b/UnitTests/MockedEventsFixture.cs index 27fef72f0..80c42f69d 100644 --- a/UnitTests/MockedEventsFixture.cs +++ b/UnitTests/MockedEventsFixture.cs @@ -35,8 +35,7 @@ public void ShouldRaiseEventIfAttachedAfterUse() Assert.False(presenter.Canceled); - view.Raise(v => v.Canceled += null, EventArgs.Empty); - + view.Raise(v => v.Canceled += null, EventArgs.Empty); Assert.True(presenter.Canceled); }