nsubstitute

Importing NSubstitute into Unity project

我是研究僧i 提交于 2021-02-19 08:21:57
问题 I'm trying to use NSubstitute in my Unity project (Unity version 2019.2.2f1). No matter how to import it, my IDE, both Visual Studio and JetBrains Rider, would give an error when I try using NSubstitute saying NSubstitute is undefined. I have tried many options and versions of NSubstitute packages (4.2.1 and 2.0.3). I also import the dll file from net35 folder of the package into a Plugins folder in my Unity project. I also tried to install the same version of NSubstitute using Nuget in the

Importing NSubstitute into Unity project

会有一股神秘感。 提交于 2021-02-19 08:21:33
问题 I'm trying to use NSubstitute in my Unity project (Unity version 2019.2.2f1). No matter how to import it, my IDE, both Visual Studio and JetBrains Rider, would give an error when I try using NSubstitute saying NSubstitute is undefined. I have tried many options and versions of NSubstitute packages (4.2.1 and 2.0.3). I also import the dll file from net35 folder of the package into a Plugins folder in my Unity project. I also tried to install the same version of NSubstitute using Nuget in the

Can I get NSubstitute to auto mock my concrete classes?

こ雲淡風輕ζ 提交于 2021-02-16 04:33:51
问题 I have an interface which I am mocking with 'NSubstitute' which contains properties that return concreate classes, that is the return value is not an interface. e.g public interface ISomething { SomeObj First { get; } SomeObj Second { get; } } The 'SomeObj' concrete class has a default constructor but 'NSubstitute' always returns 'null' for these properties. The class itself is not under my control so I cannot simply make it derive from an interface. Can 'NSubstitute' mock these type of

Can I get NSubstitute to auto mock my concrete classes?

五迷三道 提交于 2021-02-16 04:31:06
问题 I have an interface which I am mocking with 'NSubstitute' which contains properties that return concreate classes, that is the return value is not an interface. e.g public interface ISomething { SomeObj First { get; } SomeObj Second { get; } } The 'SomeObj' concrete class has a default constructor but 'NSubstitute' always returns 'null' for these properties. The class itself is not under my control so I cannot simply make it derive from an interface. Can 'NSubstitute' mock these type of

NSubstitute ILogger .NET Core

我是研究僧i 提交于 2020-08-04 06:25:20
问题 I am trying to write unit tests around my exception handling so that I can verify the my logger is properly logging the exception. I am using NSubstitute as a mocking framework and Microsoft.Extensions.Logging.ILogger I have to following for my test: [Fact] public void LogsExcpetionWhenErrorOccursInCreate() { var newUser = new UserDataModel { FirstName = "Rick", MiddleName = "Jason", LastName = "Grimes", Email = "rick.grimes@thedead.com", Created = new DateTime(2007, 8, 15) }; var exception =

NSubstitute ILogger .NET Core

两盒软妹~` 提交于 2020-08-04 06:21:23
问题 I am trying to write unit tests around my exception handling so that I can verify the my logger is properly logging the exception. I am using NSubstitute as a mocking framework and Microsoft.Extensions.Logging.ILogger I have to following for my test: [Fact] public void LogsExcpetionWhenErrorOccursInCreate() { var newUser = new UserDataModel { FirstName = "Rick", MiddleName = "Jason", LastName = "Grimes", Email = "rick.grimes@thedead.com", Created = new DateTime(2007, 8, 15) }; var exception =

NSubstitute multiple return sequence

ⅰ亾dé卋堺 提交于 2020-07-18 11:37:42
问题 I want to substitute object to return sequence of different objects. For example: var http = Substitute.For<IHttp>(); http.GetResponse(Arg.Any<string>()).Returns(resourceString, resourceString2); http.GetResponse(Arg.Any<string>()).Returns(x => { throw new Exception(); }); will return resourceString then resourceString2 then exception. Or something like this: var http = Substitute.For<IHttp>(); http.GetResponse(Arg.Any<string>()).Returns(resourceString, x => { throw new Exception(); },

NSubstitute multiple return sequence

孤者浪人 提交于 2020-07-18 11:36:55
问题 I want to substitute object to return sequence of different objects. For example: var http = Substitute.For<IHttp>(); http.GetResponse(Arg.Any<string>()).Returns(resourceString, resourceString2); http.GetResponse(Arg.Any<string>()).Returns(x => { throw new Exception(); }); will return resourceString then resourceString2 then exception. Or something like this: var http = Substitute.For<IHttp>(); http.GetResponse(Arg.Any<string>()).Returns(resourceString, x => { throw new Exception(); },

Internal properties are not handled by NSubstitute

╄→гoц情女王★ 提交于 2020-06-26 06:59:24
问题 Suppose, that I've got a following class: public abstract class Test { internal abstract int Prop { get; } } Now, I try to make a mock using NSubstitute: var mock = Substitute.For<Test>(); But that fails: Method 'get_Prop' in type 'Castle.Proxies.TestProxy' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a621a9e7e5c32e69' does not have an implementation. I thought of adding NSubstitute to [InternalsVisibleTo] , but unfortunately my tested assembly is