public void CreateMedicalVendorInvoiceItemSetsDomainPropertiesToRowPropertiesCorrectly() { const long customerId = 1; var evaluationStartTime = new DateTime(2003, 5, 4); const decimal medicalVendorAmountEarned = 23.55m; AddRowToMedicalVendorInvoiceItemTypedView(customerId, evaluationStartTime, medicalVendorAmountEarned); Expect.Call(_medicalVendorMedicalVendorUserFactory.CreateMedicalVendorMedicalVendorUser((MedicalVendorInvoiceItemRow)null)). IgnoreArguments().Return(new MedicalVendorMedicalVendorUser { Name = new Name() }); _mocks.ReplayAll(); MedicalVendorInvoiceItem medicalVendorInvoiceItem = _medicalVendorInvoiceItemFactory. CreateMedicalVendorInvoiceItem(_medicalVendorInvoiceItemTypedView[0]); _mocks.VerifyAll(); Assert.AreEqual(customerId, medicalVendorInvoiceItem.CustomerId); Assert.AreEqual(evaluationStartTime, medicalVendorInvoiceItem.EvaluationStartTime); Assert.AreEqual(medicalVendorAmountEarned, medicalVendorInvoiceItem.MedicalVendorAmountEarned); }
public void Redirect_OneArgumentWithArea_Redirects() { ActionArgument argument = new ActionArgument(0, "name", "Jacob"); New("Area", "Controller", "Action", argument); using (_mocks.Unordered()) { SetupMocks(); Expect.Call(_argumentConversionService.ConvertArgument(null, argument, _parameters)).Return(true); Expect.Call(_serverUtility.UrlEncode("name")).Return("name"); Expect.Call(_serverUtility.UrlEncode("Jacob")).Return("Jacob"); _parameters.Add("name", "Jacob"); } _mocks.ReplayAll(); _reference.Redirect(); _mocks.VerifyAll(); Assert.IsTrue(this._controller.Context.Response.WasRedirected); Assert.AreEqual("/Area/Controller/Action.rails?name=Jacob", _response.RedirectedTo); }
public void SingleSessionAppliesDefaultFlushModeOnOpenSessionAndClosesSession() { ISession expectedSession = (ISession)repository.CreateMock(typeof(ISession)); Expect.Call(expectedSessionFactory.OpenSession()).Return(expectedSession); expectedSession.FlushMode = FlushMode.Auto; Expect.Call(expectedSession.Close()).Return(null); repository.ReplayAll(); SessionScope scope = null; using (scope = new SessionScope(expectedSessionFactory, null, true, FlushMode.Auto, true)) { SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory); Assert.IsTrue(sessionHolder.ContainsSession(expectedSession)); } // ensure scope is closed and sessionHolder is unregistered from TSM Assert.IsFalse(scope.IsOpen); Assert.IsFalse(TransactionSynchronizationManager.HasResource(expectedSessionFactory)); repository.VerifyAll(); }
public void GetHttpVersion_Test() { MockRepository mocks = new MockRepository(); IAspNetRuntime aspNetRuntime = mocks.CreateMock <IAspNetRuntime>(); ITransaction transaction = mocks.CreateMock <ITransaction>(); IResponse response = mocks.CreateMock <IResponse>(); IRequest request = mocks.CreateMock <IRequest>(); using (mocks.Unordered()) { Expect.Call(request.RawUrl).Return("/foo/").Repeat.Any(); Expect.Call(request.HttpVersion).Return("HTTP/1.1").Repeat.Any(); Expect.Call(transaction.Request).Return(request).Repeat.Any(); Expect.Call(transaction.Response).Return(response).Repeat.Any(); Expect.Call(delegate { aspNetRuntime.ProcessRequest(null); }).IgnoreArguments(); } mocks.ReplayAll(); AspNetWorker aspNetWorker = new AspNetWorker(aspNetRuntime, "/foo", @"c:\temp"); aspNetWorker.ProcessTransaction(transaction); Assert.AreEqual("HTTP/1.1", aspNetWorker.GetHttpVersion()); }
public void FlushResponse_Is_Final_Test() { MockRepository mocks = new MockRepository(); IAspNetRuntime aspNetRuntime = mocks.CreateMock <IAspNetRuntime>(); ITransaction transaction = mocks.CreateMock <ITransaction>(); IResponse response = mocks.CreateMock <IResponse>(); IRequest request = mocks.CreateMock <IRequest>(); using (mocks.Unordered()) { Expect.Call(request.RawUrl).Return("/test/").Repeat.Any(); Expect.Call(transaction.Request).Return(request).Repeat.Any(); Expect.Call(transaction.Response).Return(response).Repeat.Any(); Expect.Call(delegate { aspNetRuntime.ProcessRequest(null); }).IgnoreArguments(); Expect.Call(delegate { response.Flush(); }).IgnoreArguments(); } mocks.ReplayAll(); AspNetWorker aspNetWorker = new AspNetWorker(aspNetRuntime, "/", @"c:\temp"); aspNetWorker.ProcessTransaction(transaction); aspNetWorker.FlushResponse(true); }
private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(MockRepository mocks, IDemo demo, IEditableObject editable) { Assert.NotNull(demo); Assert.NotNull(editable); // Set expectation on one member on each interface Expect.Call(demo.ReadOnly).Return("foo"); editable.BeginEdit(); mocks.ReplayAll(); // Drive two members on each interface to check dynamic nature Assert.Equal("foo", demo.ReadOnly); demo.VoidNoArgs(); editable.BeginEdit(); editable.EndEdit(); mocks.VerifyAll(); }
public void Read_SingleMessageInTwoParts() { var mocks = new MockRepository(); var adapter = mocks.PartialMock <CrossPlatformUdpClient>(new UdpClient()); Expect.Call(adapter.Read()) .Return(new List <byte>(new byte[] { 1, 2, 3, 4, 5 })); mocks.ReplayAll(); var buffer = new byte[5]; // read first part of message Assert.AreEqual(3, adapter.Read(buffer, 0, 3)); // read remainder Assert.AreEqual(2, adapter.Read(buffer, 3, 2)); Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5 }, buffer); mocks.VerifyAll(); }
public void RenderMailMessage_MessageIsConstructedCorrectly() { const string templateName = "welcome"; var parameters = new Hashtable(); using (mockRepository.Record()) { Expect.Call(viewEngineManagerMock.HasTemplate("mail\\" + templateName)).Return(true); Expect.Call(() => viewEngineManagerMock.Process(templateName, "layout", null, null)) .Constraints( Is.Equal("mail\\" + templateName), Is.Equal("layout"), Is.Anything(), Is.Anything()) .Do(new Render(RendersEmail)); } using (mockRepository.Playback()) { var message = service.RenderMailMessage(templateName, "layout", parameters); Assert.AreEqual("*****@*****.**", message.To[0].Address); Assert.AreEqual("*****@*****.**", message.CC[0].Address); Assert.AreEqual("*****@*****.**", message.Bcc[0].Address); Assert.AreEqual("*****@*****.**", message.From.Address); Assert.AreEqual("Hello!", message.Subject); Assert.AreEqual("This is the\r\nbody\r\n", message.Body); Assert.AreEqual(1, message.Headers.Count); #if !DOTNET40 Assert.AreEqual("Test Reply", message.ReplyTo.DisplayName); Assert.AreEqual("*****@*****.**", message.ReplyTo.Address); #else Assert.AreEqual(1, message.ReplyToList.Count()); Assert.AreEqual("Test Reply", message.ReplyToList.First().DisplayName); Assert.AreEqual("*****@*****.**", message.ReplyToList.First().Address); #endif } }
public void RenderMailMessage_BackwardCompatibility_UsesTemplateNameAsItIsIfStartsWithSlash() { const string templateName = "/emailtemplates/welcome"; using (mockRepository.Record()) { Expect.Call(viewEngineManagerMock.HasTemplate(templateName)).Return(true); viewEngineManagerMock.Process(templateName, null, engineContext, controller, controllerContext); LastCall.Constraints( Is.Equal(templateName), Is.Anything(), Is.Same(engineContext), Is.Same(controller), Is.Same(controllerContext)); } using (mockRepository.Playback()) { service.RenderMailMessage(templateName, engineContext, controller, controllerContext, false); } }
public void ShouldCorrectlyBuild() { var mocks = new MockRepository(); var generator = mocks.StrictMock <INumberGenerator>(); ICalendar calendar = new StubbedCalendar(new DateTime(2000, 1, 1)); Expect.Call(generator.GenerateNumber()).Return("124"); mocks.ReplayAll(); var builder = new ExpenseReportBuilder(generator, calendar); var creator = new Employee(); ExpenseReport expenseReport = builder.Build(creator); mocks.VerifyAll(); Assert.That(expenseReport.Submitter, Is.EqualTo(creator)); Assert.That(expenseReport.Number, Is.EqualTo("124")); Assert.That(expenseReport.Approver, Is.Null); Assert.That(expenseReport.Title, Is.Empty); Assert.That(expenseReport.Description, Is.Empty); Assert.That(expenseReport.Status, Is.EqualTo(ExpenseReportStatus.Draft)); Assert.That(expenseReport.Created, Is.EqualTo(new DateTime(2000, 1, 1))); }
public void Should_leverage_repository_to_update_the_customer_information() { int customerId = 1; ICustomer customer = _mockery.DynamicMock <ICustomer>( ); IRegistration registration = _mockery.DynamicMock <IRegistration>( ); using (_mockery.Record( )) { SetupResult.For(customer.Registration( )).Return(registration); SetupResult.For(registration.IsValid( )).Return(true); using (_mockery.Ordered( )) { Expect.Call(_mockCustomerRepository.FindBy(customerId)).Return(customer); customer.UpdateRegistrationTo("mokhan", "password", "mo", "khan", "4036813389", "calgary"); _mockCustomerRepository.Save(customer); } } using (_mockery.Playback( )) { CreateSUT( ).UpdateRegistrationFor( new UpdateCustomerRegistrationDTO(1, "mokhan", "password", "mo", "khan", "4036813389", "calgary")); } }
public void InsertSecondRecordDoesNotReopenTable() { var stubTransaction = this.mocks.Stub <Transaction>(); var stubTable = this.mocks.Stub <Table>(); var stubRecord = this.mocks.Stub <Record>(); Expect.Call(this.mockConnection.BeginTransaction()).Return(stubTransaction); Expect.Call(this.mockConnection.OpenTable("stubtable")).Return(stubTable); SetupResult.For(stubTable.NewRecord()).Return(stubRecord); SetupResult.For(stubTable.TableName).Return("stubtable"); var data = new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("mycolumn", "somedata"), }; this.mocks.ReplayAll(); this.sqlImpl.BeginTransaction(); this.sqlImpl.InsertRecord("stubtable", data); this.sqlImpl.InsertRecord("stubtable", data); this.mocks.VerifyAll(); }
public void RollbackTransactionTwiceThrowsException() { var mockTransaction = this.mocks.StrictMock <Transaction>(); SetupResult.For(this.mockConnection.BeginTransaction()).Return(mockTransaction); Expect.Call(() => mockTransaction.Rollback()); this.mocks.ReplayAll(); this.sqlImpl.BeginTransaction(); this.sqlImpl.RollbackTransaction(); try { this.sqlImpl.RollbackTransaction(); Assert.Fail("Expected an EsentSqlExecutionException"); } catch (EsentSqlExecutionException) { } this.mocks.VerifyAll(); }
public void SessionFactoryUtilsWithGetDbProvider() { MockRepository mockery = new MockRepository(); ISessionFactoryImplementor sessionFactory = (ISessionFactoryImplementor)mockery.CreateMultiMock(typeof(ISessionFactory), typeof(ISessionFactoryImplementor)); IDriver driver = (IDriver)mockery.DynamicMock(typeof(IDriver)); Expect.Call(driver.CreateCommand()).Repeat.AtLeastOnce().Return(new SqlCommand()); IConnectionProvider cp = (IConnectionProvider)mockery.DynamicMock(typeof(IConnectionProvider)); Expect.Call(cp.Driver).Repeat.AtLeastOnce().Return(driver); Expect.Call(sessionFactory.ConnectionProvider).Repeat.AtLeastOnce().Return(cp); mockery.ReplayAll(); IDbProvider provider = SessionFactoryUtils.GetDbProvider(sessionFactory); Assert.AreEqual(typeof(SqlCommand), provider.DbMetadata.CommandType); mockery.VerifyAll(); }
public void DictionaryConversionWhereMapHasNonStringTypesForKeys() { IMapMessage message = (IMapMessage)mocks.CreateMock(typeof(IMapMessage)); Expect.Call(session.CreateMapMessage()).Return(message); mocks.ReplayAll(); IDictionary content = new Hashtable(); content.Add(new Cafe(), "value1"); try { converter.ToMessage(content, session); Assert.Fail("Should have thrown MessageConversionException"); } catch (MessageConversionException) { } mocks.VerifyAll(); }
public void RenderMailMessage_InvokesViewEngineManager() { const string templateName = "welcome"; var parameters = new Hashtable(); using (mockRepository.Record()) { Expect.Call(viewEngineManagerMock.HasTemplate("mail\\" + templateName)).Return(true); viewEngineManagerMock.Process(templateName, "layout", null, null); LastCall.Constraints( Is.Equal("mail\\" + templateName), Is.Equal("layout"), Is.Anything(), Is.Anything()); } using (mockRepository.Playback()) { service.RenderMailMessage(templateName, "layout", parameters); } }
public void InvalidSignatureThrows() { var repository = new MockRepository(); var consumerStore = repository.DynamicMock <IConsumerStore>(); var signer = repository.StrictMock <IOAuthContextSigner>(); var context = new OAuthContext { ConsumerKey = "key", SignatureMethod = SignatureMethod.PlainText }; using (repository.Record()) { Expect.Call(signer.ValidateSignature(null, null)).IgnoreArguments().Return(false); } using (repository.Playback()) { var inspector = new SignatureValidationInspector(consumerStore, signer); var ex = Assert.Throws <OAuthException>(() => inspector.InspectContext(ProviderPhase.GrantRequestToken, context)); Assert.Equal("Failed to validate signature", ex.Message); } }
public void ApplyParametersHandlesParameter() { var dynamicValue = mocks.StrictMock <IDynamicValue>(); var task = new TestTask { DynamicValues = new IDynamicValue[] { dynamicValue } }; var parameters = new Dictionary <string, string>(); var definitions = new List <ParameterBase>(); Expect.Call(() => { dynamicValue.ApplyTo(task, parameters, definitions); }); mocks.ReplayAll(); task.ApplyParameters(parameters, definitions); mocks.VerifyAll(); }