public virtual void SetUp() { TestRunnerManager.Reset(); MockRepository = new MockRepository(); // FeatureContext and ScenarioContext is needed, because the [Binding]-instances live there FeatureLanguage = GetFeatureLanguage(); CultureInfo bindingCulture = GetBindingCulture(); var testThreadContainer = new ObjectContainer(); testThreadContainer.RegisterInstanceAs(new Mock <ITestRunner>().Object); testThreadContainer.RegisterTypeAs <BindingInstanceResolver, IBindingInstanceResolver>(); var containerBuilderMock = new Mock <IContainerBuilder>(); containerBuilderMock.Setup(m => m.CreateScenarioContainer(It.IsAny <IObjectContainer>(), It.IsAny <ScenarioInfo>())) .Returns((IObjectContainer ttc, ScenarioInfo si) => { var scenarioContainer = new ObjectContainer(ttc); scenarioContainer.RegisterInstanceAs(si); return(scenarioContainer); }); ContextManagerStub = new ContextManager(MockRepository.Stub <ITestTracer>(), testThreadContainer, containerBuilderMock.Object); ContextManagerStub.InitializeFeatureContext(new FeatureInfo(FeatureLanguage, "test feature", null), bindingCulture); ContextManagerStub.InitializeScenarioContext(new ScenarioInfo("test scenario")); StepArgumentTypeConverterStub = MockRepository.Stub <IStepArgumentTypeConverter>(); }
public void ReturnsAnAcceptableLocationWhenOneIsAvailable() { var mocks = new Rhino.Mocks.MockRepository(); var db = (null as ILocationRepository).Create(mocks); var allLocations = new List <Location>(); allLocations.Add((null as Location).Create(1.01f, 6.5)); TestContext.WriteLine(allLocations.Print()); Rhino.Mocks .Expect.Call(db.GetLocations()) .Repeat.Any() .Return(allLocations); mocks.ReplayAll(); var target = new Engine(db); var actual = target.Scout(); Assert.AreEqual(1, actual.Count()); mocks.VerifyAll(); }
public void ReturnOnlyLocationsWithGravityLessThan105PercentOfStandard() { var mocks = new Rhino.Mocks.MockRepository(); var db = (null as ILocationRepository).Create(mocks); int locationCount = 100.GetRandom(50); var allLocations = new List<Location>(); for (int i = 0; i < locationCount; i++) allLocations.Add((null as Location).Create()); TestContext.WriteLine("{0} locations in data store", allLocations.Count()); Rhino.Mocks .Expect.Call(db.GetLocations()) .Repeat.Any() .Return(allLocations); mocks.ReplayAll(); var target = new Engine(db); var actual = target.Scout(); TestContext.WriteLine("{0} locations returned from target", actual.Count()); foreach (var location in actual) Assert.IsTrue(location.Gravity < 1.05); mocks.VerifyAll(); }
public void TestDequeue( ) { Rhino.Mocks.MockRepository oMocks = new Rhino.Mocks.MockRepository( ); Utility.IXmlFilePersister oXmlFilePersister = oMocks.StrictMock <Utility.IXmlFilePersister> ( ); using (oMocks.Record( )) { Rhino.Mocks.Expect .Call(oXmlFilePersister.Load("")) .IgnoreArguments( ) .Return(System.Xml.Linq.XElement.Parse("<Waitlist><Persons><Person Id=\"47a73298-d91c-4c94-80aa-d935c9b0873e\"><Name>50ffab1f-b894-4632-898d-2c6588856641</Name><Phone>5be558b7-2c57-4156-96e0-d2442bc41975</Phone></Person></Persons></Waitlist>")); Rhino.Mocks.Expect .Call(() => oXmlFilePersister.Save("", null)) .IgnoreArguments( ); } using (oMocks.Playback( )) { Service.Waitlist svc = new Service.Waitlist(oXmlFilePersister); svc.Dequeue(new Data.Person( ) { Id = new Guid("47a73298-d91c-4c94-80aa-d935c9b0873e"), Name = "50ffab1f-b894-4632-898d-2c6588856641", Phone = "5be558b7-2c57-4156-96e0-d2442bc41975" }); } }
public void TestLoad( ) { Rhino.Mocks.MockRepository oMocks = new Rhino.Mocks.MockRepository( ); Utility.IXmlFilePersister oXmlFilePersister = oMocks.StrictMock <Utility.IXmlFilePersister> ( ); using (oMocks.Record( )) { Rhino.Mocks.Expect .Call(oXmlFilePersister.Load("")) .IgnoreArguments( ) .Return(System.Xml.Linq.XElement.Parse("<Waitlist><Persons><Person Id=\"47a73298-d91c-4c94-80aa-d935c9b0873e\"><Name>50ffab1f-b894-4632-898d-2c6588856641</Name><Phone>5be558b7-2c57-4156-96e0-d2442bc41975</Phone></Person></Persons></Waitlist>")); } using (oMocks.Playback( )) { Service.Waitlist svc = new Service.Waitlist(oXmlFilePersister); Data.Person [] aPersons = svc.GetAll( ); Assert.IsNotNull(aPersons); Assert.AreEqual(1, aPersons.Length); Assert.AreEqual(new Guid("47a73298-d91c-4c94-80aa-d935c9b0873e"), aPersons [0].Id); Assert.AreEqual("50ffab1f-b894-4632-898d-2c6588856641", aPersons [0].Name); Assert.AreEqual("5be558b7-2c57-4156-96e0-d2442bc41975", aPersons [0].Phone); } }
public void TestQueueWithEmptyList( ) { Rhino.Mocks.MockRepository oMocks = new Rhino.Mocks.MockRepository( ); Utility.IXmlFilePersister oXmlFilePersister = oMocks.StrictMock <Utility.IXmlFilePersister> ( ); using (oMocks.Record( )) { Rhino.Mocks.Expect .Call(oXmlFilePersister.Load("")) .IgnoreArguments( ) .Return(null); Rhino.Mocks.Expect .Call(() => oXmlFilePersister.Save("", null)) .IgnoreArguments( ); } using (oMocks.Playback( )) { Service.Waitlist svc = new Service.Waitlist(oXmlFilePersister); string sName = Guid.NewGuid( ).ToString( ); string sPhone = Guid.NewGuid( ).ToString( ); Data.Person dPerson = svc.Queue(sName, sPhone); Assert.IsNotNull(dPerson); Assert.AreEqual(sName, dPerson.Name); Assert.AreEqual(sPhone, dPerson.Phone); Assert.AreNotEqual(Guid.Empty, dPerson.Id); } }
public void ReturnOnlyLocationsWithPopulationDensityGreaterThanOne() { var mocks = new Rhino.Mocks.MockRepository(); var db = (null as ILocationRepository).Create(mocks); int locationCount = 100.GetRandom(50); var allLocations = new List <Location>(); for (int i = 0; i < locationCount; i++) { allLocations.Add((null as Location).Create()); } TestContext.WriteLine("{0} locations in data store", allLocations.Count()); TestContext.WriteLine(allLocations.Print()); Rhino.Mocks .Expect.Call(db.GetLocations()) .Repeat.Any() .Return(allLocations); mocks.ReplayAll(); var target = new Engine(db); var actual = target.Scout(); TestContext.WriteLine("{0} locations returned from target", actual.Count()); foreach (var location in actual) { Assert.IsTrue(location.PopulationDensity > 1.0); } mocks.VerifyAll(); }
public void TestDequeueWithEmptyList( ) { Rhino.Mocks.MockRepository oMocks = new Rhino.Mocks.MockRepository( ); Utility.IXmlFilePersister oXmlFilePersister = oMocks.StrictMock <Utility.IXmlFilePersister> ( ); using (oMocks.Record( )) { Rhino.Mocks.Expect .Call(oXmlFilePersister.Load("")) .IgnoreArguments( ) .Return(null); Rhino.Mocks.Expect .Call(() => oXmlFilePersister.Save("", null)) .IgnoreArguments( ); } using (oMocks.Playback( )) { Service.Waitlist svc = new Service.Waitlist(oXmlFilePersister); svc.Dequeue(new Data.Person( ) { Id = Guid.NewGuid( ), Name = Guid.NewGuid( ).ToString( ), Phone = Guid.NewGuid( ).ToString( ) }); } }
public void Realizar_Consulta_De_Cantidad_De_Peliculas_De_Un_Director() { Rhino.Mocks.MockRepository mock = new Rhino.Mocks.MockRepository(); KataPeliculas.IDbContexto context = mock.DynamicMock<IDbContexto>(); Rhino.Mocks.Expect.Call(context.ObtenerCantidadPeliculasPorDirector("ROBERT ZEMECKIS")).IgnoreArguments().Return(1); mock.ReplayAll(); int cantidad = context.ObtenerCantidadPeliculasPorDirector("ROBERT ZEMECKIS"); Assert.AreEqual(1, cantidad); }
public void Enviar() { try { Rhino.Mocks.MockRepository mock = new Rhino.Mocks.MockRepository(); IEmail mail = mock.DynamicMock<IEmail>(servidor, from, to); Rhino.Mocks.Expect.Call<IEmail>(mail).IgnoreArguments().Throw(new Exception("Error al Enviar Correo")); mail.Enviar(mensaje, asunto); } catch { //OK } }
public void Commit_En_Base_De_Datos() { try { Rhino.Mocks.MockRepository mock = new Rhino.Mocks.MockRepository(); KataPeliculas.IDbContexto context = mock.DynamicMock<IDbContexto>(); Rhino.Mocks.Expect.Call<IDbContexto>(context).IgnoreArguments().Throw(new Exception("Error al hacer commit")); context.Commit(); } catch { //OK } }
public void CallWriteLineOnTheTestContextExactlyOnce() { var mocks = new Rhino.Mocks.MockRepository(); var testContext = mocks.StrictMock<Microsoft.VisualStudio.TestTools.UnitTesting.TestContext>(); testContext.WriteLine(string.Empty, null); Rhino.Mocks.LastCall.IgnoreArguments().Repeat.Once(); mocks.ReplayAll(); string message = string.Empty.GetRandom(); var target = new LiquidNun.Logging.TestContext.Provider(testContext); target.LogInformation("Category", "Title", message); mocks.VerifyAll(); }
public void CallWriteLineOnTheTestContextExactlyOnce() { var mocks = new Rhino.Mocks.MockRepository(); var testContext = mocks.StrictMock <Microsoft.VisualStudio.TestTools.UnitTesting.TestContext>(); testContext.WriteLine(string.Empty, null); Rhino.Mocks.LastCall.IgnoreArguments().Repeat.Once(); mocks.ReplayAll(); string message = string.Empty.GetRandom(); var target = new LiquidNun.Logging.TestContext.Provider(testContext); target.LogInformation("Category", "Title", message); mocks.VerifyAll(); }
public virtual void SetUp() { TestRunnerManager.Reset(); MockRepository = new MockRepository(); // FeatureContext and ScenarioContext is needed, because the [Binding]-instances live there FeatureLanguage = GetFeatureLanguage(); CultureInfo bindingCulture = GetBindingCulture(); var container = new ObjectContainer(); container.RegisterInstanceAs(new Mock <ITestRunner>().Object); ContextManagerStub = new ContextManager(MockRepository.Stub <ITestTracer>(), container); ContextManagerStub.InitializeFeatureContext(new FeatureInfo(FeatureLanguage, "test feature", null), bindingCulture); ContextManagerStub.InitializeScenarioContext(new ScenarioInfo("test scenario")); StepArgumentTypeConverterStub = MockRepository.Stub <IStepArgumentTypeConverter>(); }
public void IncludeTheMessageInWhatIsWritten() { var mocks = new Rhino.Mocks.MockRepository(); var tc = mocks.StrictMock<Microsoft.VisualStudio.TestTools.UnitTesting.TestContext>(); string message = string.Empty.GetRandom(); tc.WriteLine(string.Empty, null); Rhino.Mocks.LastCall.IgnoreArguments() .Constraints( Rhino.Mocks.Constraints.Is.Anything(), Rhino.Mocks.Constraints.List.IsIn(message)) .Repeat.Once(); mocks.ReplayAll(); var target = new LiquidNun.Logging.TestContext.Provider(tc); target.LogInformation("Category", "Title", message); mocks.VerifyAll(); }
public void IncludeTheMessageInWhatIsWritten() { var mocks = new Rhino.Mocks.MockRepository(); var tc = mocks.StrictMock <Microsoft.VisualStudio.TestTools.UnitTesting.TestContext>(); string message = string.Empty.GetRandom(); tc.WriteLine(string.Empty, null); Rhino.Mocks.LastCall.IgnoreArguments() .Constraints( Rhino.Mocks.Constraints.Is.Anything(), Rhino.Mocks.Constraints.List.IsIn(message)) .Repeat.Once(); mocks.ReplayAll(); var target = new LiquidNun.Logging.TestContext.Provider(tc); target.LogInformation("Category", "Title", message); mocks.VerifyAll(); }
public virtual void SetUp() { TestRunnerManager.Reset(); MockRepository = new MockRepository(); // FeatureContext and ScenarioContext is needed, because the [Binding]-instances live there FeatureLanguage = GetFeatureLanguage(); var runtimeConfiguration = ConfigurationLoader.GetDefault(); runtimeConfiguration.BindingCulture = GetBindingCulture(); TestThreadContainer = new ObjectContainer(); TestThreadContainer.RegisterInstanceAs(runtimeConfiguration); TestThreadContainer.RegisterInstanceAs(new Mock <ITestRunner>().Object); TestThreadContainer.RegisterTypeAs <TestObjectResolver, ITestObjectResolver>(); var containerBuilderMock = new Mock <IContainerBuilder>(); containerBuilderMock.Setup(m => m.CreateScenarioContainer(It.IsAny <IObjectContainer>(), It.IsAny <ScenarioInfo>())) .Returns((IObjectContainer fc, ScenarioInfo si) => { var scenarioContainer = new ObjectContainer(fc); scenarioContainer.RegisterInstanceAs(si); return(scenarioContainer); }); containerBuilderMock.Setup(m => m.CreateFeatureContainer(It.IsAny <IObjectContainer>(), It.IsAny <FeatureInfo>())) .Returns((IObjectContainer ttc, FeatureInfo fi) => { var featureContainer = new ObjectContainer(ttc); featureContainer.RegisterInstanceAs(fi); return(featureContainer); }); ContainerBuilderStub = containerBuilderMock.Object; ContextManagerStub = new ContextManager(MockRepository.Stub <ITestTracer>(), TestThreadContainer, ContainerBuilderStub); ContextManagerStub.InitializeFeatureContext(new FeatureInfo(FeatureLanguage, "test feature", null)); ContextManagerStub.InitializeScenarioContext(new ScenarioInfo("test scenario")); StepArgumentTypeConverterStub = MockRepository.Stub <IStepArgumentTypeConverter>(); }
public void TestEmptyLoad( ) { Rhino.Mocks.MockRepository oMocks = new Rhino.Mocks.MockRepository( ); Utility.IXmlFilePersister oXmlFilePersister = oMocks.StrictMock <Utility.IXmlFilePersister> ( ); using (oMocks.Record( )) { Rhino.Mocks.Expect .Call(oXmlFilePersister.Load("")) .IgnoreArguments( ) .Return(null); } using (oMocks.Playback( )) { Service.Waitlist svc = new Service.Waitlist(oXmlFilePersister); Service.Data.Person [] aPersons = svc.GetAll( ); Assert.IsNotNull(aPersons); Assert.IsTrue(aPersons.Length == 0); } }
public static ILocationRepository Create(this ILocationRepository repository) { var mocks = new Rhino.Mocks.MockRepository(); return (null as ILocationRepository).Create(mocks); }
public Test_Fichero_Entrada() { mock = new Rhino.Mocks.MockRepository(); mockficheroEntrada = mock.DynamicMock<IFicheroEntrada>(); fakeFicheroEntrada = new FicheroEntradaStub(); }
public void ReturnsAnAcceptableLocationWhenOneIsAvailable() { var mocks = new Rhino.Mocks.MockRepository(); var db = (null as ILocationRepository).Create(mocks); var allLocations = new List<Location>(); allLocations.Add((null as Location).Create(1.01f, 6.5)); TestContext.WriteLine(allLocations.Print()); Rhino.Mocks .Expect.Call(db.GetLocations()) .Repeat.Any() .Return(allLocations); mocks.ReplayAll(); var target = new Engine(db); var actual = target.Scout(); Assert.AreEqual(1, actual.Count()); mocks.VerifyAll(); }
public static ILocationRepository Create(this ILocationRepository repository, Rhino.Mocks.MockRepository mockRepository) { return(mockRepository.DynamicMock <ILocationRepository>()); }
public static ILocationRepository Create(this ILocationRepository repository) { var mocks = new Rhino.Mocks.MockRepository(); return((null as ILocationRepository).Create(mocks)); }
public Test_Sobre_BBDD_Datos() { mock = new Rhino.Mocks.MockRepository(); context = mock.DynamicMock<IDbContexto>(); }