public void DefaultUsingTest() { var factory = new MockFactory(MockBehavior.Loose); // Bool option var mockBoolOption = factory.Create <BoolOption>("verbose"); var boolOption = mockBoolOption.Object.IsRequired().SetSynonyms("-v", "--verbose"); // Int option const int minValue = 10; const int maxValue = 100; var mockIntOption = factory.Create <RangeOption <int> >("size"); var intOption = mockIntOption.Object.SetMinValue(minValue).SetMaxValue(maxValue).SetSynonyms("-s", "--size"); // Enum Option var mockEnumOption = factory.Create <EnumOption>("enumerate"); var enumOption = mockEnumOption.Object.SetValues("first", "second", "third").IsRequired().SetSynonyms("-e", "--enumerate"); Assert.That(enumOption.Synonyms.Count(), Is.EqualTo(2)); // Parser string[] cmdArguments = "--verbose -s=20 -e aaa".Split(' '); var parser = new Parser(cmdArguments); parser.AddKnownPreference(boolOption, intOption, enumOption); parser.Parse(); // Printer using (var printer = new Printer(Console.Out)) { printer.WriteOptions(parser.Options); } }
public void AddContent_WithHttpWebRequestAdapterAndHttpRequest() { // Arrange Mock <IHttpWebRequestAdapter> mockHttpWebRequest = mocks.Create <IHttpWebRequestAdapter>(); HttpRequest request = new HttpRequest() { Content = "content", ContentEncoding = Encoding.UTF8, ContentType = "application/xml" }; Stream stream = new MemoryStream(); mockHttpWebRequest.Setup(wr => wr.GetRequestStream()).Returns(stream); mockHttpWebRequest.SetupSet(wr => wr.ContentLength = request.ContentLength); mockHttpWebRequest.SetupSet(wr => wr.ContentType = request.ContentType); // Act helper.AddContent(mockHttpWebRequest.Object, request); // Assert // Expectations have been met. }
public void Setup() { _factory = new MockFactory(MockBehavior.Strict); _parserMock = _factory.Create<IConfigurationParser>(); _proxyMock = _factory.Create<IConfigurationProxyProvider>(); _sage = new Sage(_parserMock.Object, _proxyMock.Object); }
private static void fakeDevice(ContainerBuilder builder) { MockFactory moqfactory = new MockFactory(MockBehavior.Loose); builder.Register <ICash>(c => moqfactory.Create <ICash>().Object).PropertiesAutowired(); builder.Register <IBarScanner>(c => moqfactory.Create <IBarScanner>().Object).PropertiesAutowired(); builder.Register <IDisplayCustomer>(c => moqfactory.Create <IDisplayCustomer>().Object).PropertiesAutowired(); }
public void TestInitialize() { mocks = new MockFactory(MockBehavior.Strict); mockSerialiser = mocks.Create <ISerialiser>(); mockRestClient = mocks.Create <IRestClient>(); service = new InboxService(mockRestClient.Object, mockSerialiser.Object); }
public void SetUp() { mocks = new MockFactory(MockBehavior.Strict); folder = mocks.Create <IFolder>(); commands = mocks.Create <ICommands>(); folder.Setup(x => x.Count).Returns(0); folder.Setup(x => x.FullPath).Returns(Path.Combine("/my_server/", folderName)); commands.Setup(x => x.List(Path.Combine("/my_server/", folderName))).AtMostOnce(); }
public void TestInitialize() { mocks = new MockFactory(MockBehavior.Strict); mockHttpRequestHelper = mocks.Create <IHttpRequestHelper>(); mockHttpResponseHelper = mocks.Create <IHttpResponseHelper>(); mockEsendexCredentials = mocks.Create <EsendexCredentials>(); Uri uri = new UriBuilder("http", "tempuri.org").Uri; client = new HttpClient(mockEsendexCredentials.Object, uri, mockHttpRequestHelper.Object, mockHttpResponseHelper.Object); }
public void Submit_WithHttpRequest_ReturnsHttpResponse() { // Arrange HttpRequest request = new HttpRequest() { ResourcePath = "resource", HttpMethod = HttpMethod.POST, Content = "content", ContentEncoding = Encoding.UTF8, ContentType = "application/xml" }; HttpResponse expectedResponse = new HttpResponse() { StatusCode = HttpStatusCode.OK, Content = "content" }; Mock <IHttpWebRequestAdapter> mockWebRequest = mocks.Create <IHttpWebRequestAdapter>(); Mock <IHttpWebResponseAdapter> mockWebResponse = mocks.Create <IHttpWebResponseAdapter>(); mockHttpRequestHelper .Setup(rh => rh.Create(request, client.Uri)) .Returns(mockWebRequest.Object); mockHttpRequestHelper .Setup(rh => rh.AddCredentials(mockWebRequest.Object, mockEsendexCredentials.Object)); mockHttpRequestHelper .Setup(rh => rh.AddProxy(mockWebRequest.Object, mockEsendexCredentials.Object.WebProxy)); mockHttpRequestHelper .Setup(rh => rh.AddContent(mockWebRequest.Object, request)); mockWebRequest .Setup(wr => wr.GetResponse()) .Returns(mockWebResponse.Object); mockHttpResponseHelper .Setup(rh => rh.Create(mockWebResponse.Object)) .Returns(expectedResponse); // Act HttpResponse actualResponse = client.Submit(request); // Assert Assert.IsNotNull(actualResponse); Assert.AreEqual(expectedResponse.StatusCode, actualResponse.StatusCode); }
public void TryGetFieldInvalidStrictTest() { var isHeaderRecord = true; var data1 = new[] { "One", "Two" }; var data2 = new[] { "1", "2" }; var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); parserMock.Setup(m => m.Read()).Returns(() => { if (isHeaderRecord) { isHeaderRecord = false; return(data1); } return(data2); }); var reader = new CsvReader(parserMock.Object, new CsvReaderOptions { Strict = true }); reader.Read(); string field; var got = reader.TryGetField(-1, out field); Assert.IsFalse(got); Assert.IsNull(field); }
public void GetFieldByNameTest() { var isHeaderRecord = true; var data1 = new [] { "One", "Two" }; var data2 = new [] { "1", "2" }; var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); parserMock.Setup(m => m.Read()).Returns(() => { if (isHeaderRecord) { isHeaderRecord = false; return(data1); } return(data2); }); var reader = new CsvReader(parserMock.Object); reader.Read(); Assert.AreEqual(Convert.ToInt32(data2[0]), reader.GetField <int>("One")); Assert.AreEqual(Convert.ToInt32(data2[1]), reader.GetField <int>("Two")); }
public virtual void Setup() { CreateRunspace(); Mocks = new MockFactory(MockBehavior.Loose); factory = Mocks.Create<IEmailApiFactory>(); EmailApiCommand.Factory = factory.Object; client = Mocks.Create<IWebClient>(); client.SetupAllProperties(); client.Object.Headers = (Headers = new WebHeaderCollection()); factory.Setup(f => f.CreateWebClient()) .Returns(client.Object) .AtMostOnce(); }
public void shouldRedirectToReturnUrlWhenLoginIsSuccessfull() { var returnUrl = "~/Home/Index"; var mockFactory = new MockFactory(MockBehavior.Strict); var membershipService = mockFactory.Create<IMembershipBusinessLogic>(); var formsAuthenticationService = mockFactory.Create<IFormsAuthenticationService>(); membershipService.Setup(x => x.ValidateUser("username", "password")).Returns(true); formsAuthenticationService.Setup(x => x.SignIn("username", false)); var accountController = new CarbonFitness.App.Web.Controllers.AccountController(formsAuthenticationService.Object, membershipService.Object); var actionResult = accountController.LogOn(new LogOnModel {UserName = "******", Password = "******"}, returnUrl); Assert.That(((RedirectResult) actionResult).Url.Contains(returnUrl)); }
public void generate_key_manifest() { _moduleDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Modules\signing\"); _assemblyName = "EmptyModule.dll"; _modulePath = Path.Combine(_moduleDirectory, _assemblyName); ManifestCreatorProgram.Main(new[] { "rsa", _keyFileName , _moduleDirectory, _assemblyName, _issuerName }); var mockFactory = new MockFactory(MockBehavior.Strict); _signatureProvider = mockFactory.Create <ISignatureProvider>(); _signatureProvider.Setup(x => x.GetIssuer(_issuerName)).Returns( new IssuerInformation(_issuerName, new RsaSignatureAlgorithm(File.ReadAllText(_publicKeyFileName)))); _filter = new SignatureModuleFilter(_signatureProvider.Object); _manifestPath = _modulePath + ModuleManifest.ManifestFileNameSuffix; _manifestSignature = _manifestPath + ModuleManifest.ManifestSignatureFileNameSuffix; _moduleContent = File.ReadAllBytes(_modulePath); }
public void shouldAddIngredientToCurrentUser() { var mockFactory = new MockFactory(MockBehavior.Loose); var userContextMock = GetSetuppedUserContextMock(mockFactory); var userIngredientBusinessLogicMock = mockFactory.Create<IUserIngredientBusinessLogic>(); var userIngredient = new UserIngredient { User = new User {Username = "******"}, Ingredient = new Ingredient {Name = "Pannbiff"}, Measure = 100 }; userIngredientBusinessLogicMock.Setup(x => x.GetUserIngredients(It.IsAny<User>(), It.IsAny<DateTime>())).Returns(new[] {userIngredient}); userIngredientBusinessLogicMock.Setup(x => x.AddUserIngredient(It.Is<User>(u => u.Username == "myUser"), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<DateTime>())).Returns(userIngredient); var inputFoodModel = new InputFoodModel {Ingredient = "Pannbiff", Measure = 100, Date = DateTime.Now}; var model = testController(x => x.Input(inputFoodModel), userIngredientBusinessLogicMock, userContextMock); Assert.That(model, Is.Not.Null); Assert.That(model.UserIngredients, Is.Not.Null); Assert.That(model.UserIngredients.Any(x => x.Ingredient.Name == "Pannbiff")); Assert.That(model.UserIngredients.Any(x => x.Measure == 100)); userIngredientBusinessLogicMock.VerifyAll(); }
// TODO: Break down into smaller test cases public void ShouldDownloadEmptyFolder() { var cwd = Environment.CurrentDirectory; // Create FolderTransfer with destination var transfer = new FolderTransfer(commands.Object, null, folder.Object, Path.Combine(cwd, folderName)); //Set up expectations that ensure that the TransferDone event is fired Mock <IEventHandler> gui = mocks.Create <IEventHandler>(); gui.Setup(x => x.OnTransferDone()).AtMostOnce(); transfer.TransferDone += gui.Object.OnTransferDone; //Since this test empty folders we don't need childrens folder.Setup(x => x.Children).Returns(new NodeChildren(null)); Assert.That(transfer.Progress, Is.EqualTo(0.0)); Assert.That(transfer.Status, Is.EqualTo(Status.Idle)); transfer.Start(); Assert.That(transfer.Progress, Is.EqualTo(0.0)); Assert.That(transfer.Status, Is.EqualTo(Status.Pending)); folder.Raise(x => x.Updated -= null, folder.Object); Assert.That(transfer.Progress, Is.EqualTo(1.0)); Assert.That(transfer.Status, Is.EqualTo(Status.Done)); Assert.That(Directory.Exists(Path.Combine(cwd, folderName))); }
public void GetMissingFieldByNameStrictTest() { var isHeaderRecord = true; var data1 = new[] { "One", "Two" }; var data2 = new[] { "1", "2" }; var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); parserMock.Setup(m => m.Configuration).Returns(new CsvConfiguration()); parserMock.Setup(m => m.Read()).Returns(() => { if (isHeaderRecord) { isHeaderRecord = false; return(data1); } return(data2); }); var reader = new CsvReader(parserMock.Object) { Configuration = { IsStrictMode = true } }; reader.Read(); reader.GetField <string>("blah"); }
public void HasHeaderRecordTest() { var isHeaderRecord = true; var data1 = new [] { "One", "Two" }; var data2 = new [] { "1", "2" }; var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); parserMock.Setup(m => m.Configuration).Returns(new CsvConfiguration()); parserMock.Setup(m => m.Read()).Returns(() => { if (isHeaderRecord) { isHeaderRecord = false; return(data1); } return(data2); }); var reader = new CsvReader(parserMock.Object); reader.Read(); // Check to see if the header record and first record are set properly. Assert.AreEqual(Convert.ToInt32(data2[0]), reader.GetField <int>("One")); Assert.AreEqual(Convert.ToInt32(data2[1]), reader.GetField <int>("Two")); Assert.AreEqual(Convert.ToInt32(data2[0]), reader.GetField <int>(0)); Assert.AreEqual(Convert.ToInt32(data2[1]), reader.GetField <int>(1)); }
public void TryGetFieldInvalidConverterNameTest() { var isHeaderRecord = true; var data1 = new[] { "One", "Two" }; var data2 = new[] { "1", "2" }; var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); parserMock.Setup(m => m.Configuration).Returns(new CsvConfiguration()); parserMock.Setup(m => m.Read()).Returns(() => { if (isHeaderRecord) { isHeaderRecord = false; return(data1); } return(data2); }); var reader = new CsvReader(parserMock.Object); reader.Read(); int field; var got = reader.TryGetField("One", new GuidConverter(), out field); Assert.IsFalse(got); Assert.AreEqual(default(int), field); }
public void TryGetFieldStrictTest() { var isHeaderRecord = true; var data1 = new[] { "One", "Two" }; var data2 = new[] { "1", "2" }; var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); parserMock.Setup(m => m.Configuration).Returns(new CsvConfiguration()); parserMock.Setup(m => m.Read()).Returns(() => { if (isHeaderRecord) { isHeaderRecord = false; return(data1); } return(data2); }); var reader = new CsvReader(parserMock.Object) { Configuration = { IsStrictMode = true } }; reader.Read(); int field; var got = reader.TryGetField("One", out field); Assert.IsTrue(got); Assert.AreEqual(1, field); }
private IModuleFilter CreateModuleFilter(bool value) { var mock = _mockFactory.Create <IModuleFilter>(); mock.Setup(filter => filter.Matches(It.IsAny <ModuleInfo>())) .Returns(value); return(mock.Object); }
public void AddProvider() { var mockProvider = mockFactory.Create <TypeRegistrationsProvider>(); mockProvider.Setup(p => p.GetRegistrations(It.IsAny <IConfigurationSource>())).Returns(new TypeRegistration[0]).Verifiable(); locators.Add(mockProvider.Object); }
public void shouldThrowIngredientInsertionExceptionWhenInsertingFails() { var factory = new MockFactory(MockBehavior.Strict); var ingredientRepositoryMock = factory.Create<IIngredientRepository>(); ingredientRepositoryMock.Setup(x => x.SaveOrUpdate(It.IsAny<Ingredient>())).Throws(new Exception()); Assert.Throws<IngredientInsertionException>(() => new IngredientImporter(null, null, ingredientRepositoryMock.Object).SaveIngredient(new Ingredient())); }
public void TestInitialize() { mocks = new MockFactory(MockBehavior.Strict); mockHttpWebResponse = mocks.Create <IHttpWebResponseAdapter>(); helper = new HttpResponseHelper(); }
public void ShouldBeAbleToCreateAProxyForAnEnum() { var factory = new MockFactory(MockBehavior.Strict); var @enum = factory.Create<Fixtures.Language>(MockBehavior.Strict, null, null); @enum.Setup(e => e.IetfTag).Returns("CZ"); Assert.AreEqual("CZ", @enum.Object.IetfTag); }
public void HasHeaderRecordNotReadExceptionTest() { var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); var reader = new CsvReader(parserMock.Object); reader.GetField <int>(0); }
public void TestMethod1() { MockFactory factory = new MockFactory(MockBehavior.Loose); Mock <IOrder> order = factory.Create <IOrder>(); order.Setup(p => p.ShowTitle("111")).Returns("showTitle"); Assert.AreEqual("showTitle", order.Object.ShowTitle("111")); }
public void shouldGetUserFromUsername() { var mockFactory = new MockFactory(MockBehavior.Strict); var userRepositoryMock = mockFactory.Create<IUserRepository>(); userRepositoryMock.Setup(x => x.Get(It.IsAny<string>())).Returns(new User()); var userBusinessLogic = new UserBusinessLogic(userRepositoryMock.Object, null); userBusinessLogic.Get("myUser"); userRepositoryMock.VerifyAll(); }
public void Create(bool haveHistory = true) { _factory = new MockFactory(MockBehavior.Strict); _statusUtil = _factory.Create<IStatusUtil>(); if (haveHistory) { _history = _factory.Create<ITextUndoHistory>(); _operationsRaw = new UndoRedoOperations( _statusUtil.Object, FSharpOption.Create(_history.Object)); } else { _operationsRaw = new UndoRedoOperations( _statusUtil.Object, FSharpOption<ITextUndoHistory>.None); } _operations = _operationsRaw; }
public void HasHeaderRecordNotReadExceptionTest() { var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); parserMock.Setup(m => m.Configuration).Returns(new CsvConfiguration()); var reader = new CsvReader(parserMock.Object); reader.GetField <int>(0); }
public void GetTypeTest() { var data = new [] { "1", "blah", DateTime.Now.ToString(), "true", "c", "", Guid.NewGuid().ToString(), }; var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); parserMock.Setup(m => m.Configuration).Returns(new CsvConfiguration()); parserMock.Setup(m => m.Read()).Returns(data); var reader = new CsvReader(parserMock.Object); reader.Read(); Assert.AreEqual(Convert.ToInt16(data[0]), reader.GetField <short>(0)); Assert.AreEqual(Convert.ToInt16(data[0]), reader.GetField <short?>(0)); Assert.AreEqual(null, reader.GetField <short?>(5)); Assert.AreEqual(Convert.ToInt32(data[0]), reader.GetField <int>(0)); Assert.AreEqual(Convert.ToInt32(data[0]), reader.GetField <int?>(0)); Assert.AreEqual(null, reader.GetField <int?>(5)); Assert.AreEqual(Convert.ToInt64(data[0]), reader.GetField <long>(0)); Assert.AreEqual(Convert.ToInt64(data[0]), reader.GetField <long?>(0)); Assert.AreEqual(null, reader.GetField <long?>(5)); Assert.AreEqual(Convert.ToDecimal(data[0]), reader.GetField <decimal>(0)); Assert.AreEqual(Convert.ToDecimal(data[0]), reader.GetField <decimal?>(0)); Assert.AreEqual(null, reader.GetField <decimal?>(5)); Assert.AreEqual(Convert.ToSingle(data[0]), reader.GetField <float>(0)); Assert.AreEqual(Convert.ToSingle(data[0]), reader.GetField <float?>(0)); Assert.AreEqual(null, reader.GetField <float?>(5)); Assert.AreEqual(Convert.ToDouble(data[0]), reader.GetField <double>(0)); Assert.AreEqual(Convert.ToDouble(data[0]), reader.GetField <double?>(0)); Assert.AreEqual(null, reader.GetField <double?>(5)); Assert.AreEqual(data[1], reader.GetField <string>(1)); Assert.AreEqual(string.Empty, reader.GetField <string>(5)); Assert.AreEqual(Convert.ToDateTime(data[2]), reader.GetField <DateTime>(2)); Assert.AreEqual(Convert.ToDateTime(data[2]), reader.GetField <DateTime?>(2)); Assert.AreEqual(null, reader.GetField <DateTime?>(5)); Assert.AreEqual(Convert.ToBoolean(data[3]), reader.GetField <bool>(3)); Assert.AreEqual(Convert.ToBoolean(data[3]), reader.GetField <bool?>(3)); Assert.AreEqual(null, reader.GetField <bool?>(5)); Assert.AreEqual(Convert.ToChar(data[4]), reader.GetField <char>(4)); Assert.AreEqual(Convert.ToChar(data[4]), reader.GetField <char?>(4)); Assert.AreEqual(null, reader.GetField <char?>(5)); Assert.AreEqual(new Guid(data[6]), reader.GetField <Guid>(6)); Assert.AreEqual(null, reader.GetField <Guid?>(5)); }
public void GetFieldByNameNoHeaderExceptionTest() { var data = new [] { "1", "2" }; var mockFactory = new MockFactory( MockBehavior.Default ); var parserMock = mockFactory.Create<ICsvParser>(); parserMock.Setup( m => m.Read() ).Returns( () => data ); var reader = new CsvReader( parserMock.Object, new CsvReaderOptions{ HasHeaderRecord = false } ); reader.Read(); Assert.AreEqual( Convert.ToInt32( data[0] ), reader.GetField<int>( "One" ) ); }
public void shouldImportIngredients() { var factory = new MockFactory(MockBehavior.Strict); var ingredientParserMock = factory.Create<IIngredientParser>(); var ingredientFileReaderMock = factory.Create<IIngredientFileReader>(); var ingredientRepositoryMock = factory.Create<IIngredientRepository>(); const string abc = "abc"; const string fileName = "fileName"; ingredientFileReaderMock.Setup(x => x.ReadIngredientFile(fileName)).Returns(abc); const string abborre = "Abborre"; ingredientParserMock.Setup(x => x.CreateIngredientFromFileContents(abc)).Returns(new List<Ingredient> {new Ingredient {Name = abborre}}); ingredientRepositoryMock .Setup(x => x.SaveOrUpdate(It.Is<Ingredient>(y => y.Name == abborre))) .Returns(null as Ingredient); new IngredientImporter(ingredientParserMock.Object, ingredientFileReaderMock.Object, ingredientRepositoryMock.Object) .Import(fileName); factory.VerifyAll(); }
public void TestPersistWithFactory() { MockFactory factory = new MockFactory(MockBehavior.Strict); //Classes work, methods have to be virtual -> not nice var mockGateway = factory.Create<UserGateway>(); var mockValidator = factory.Create<IUserValidator>(); User user = new User(); //Excpectations mockValidator.Setup(x => x.Validate(user)).Returns(true).AtMostOnce(); mockGateway.Setup(x => x.Persist(user)).Returns(true).AtMostOnce(); //Assign gateway user.Gateway = mockGateway.Object; //Test method Assert.AreEqual(true, user.Persist(mockValidator.Object)); factory.VerifyAll(); }
public void GetFieldByIndexTest() { var data = new [] { "1", "2" }; var mockFactory = new MockFactory( MockBehavior.Default ); var parserMock = mockFactory.Create<ICsvParser>(); parserMock.Setup( m => m.Read() ).Returns( data ); var reader = new CsvReader( parserMock.Object ); reader.Read(); Assert.AreEqual( 1, reader.GetField<int>( 0 ) ); Assert.AreEqual( 2, reader.GetField<int>( 1 ) ); }
public void GetRecordWithDuplicateHeaderFields() { var data = new[] { "Field1", "Field1" }; var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); parserMock.Setup(m => m.Configuration).Returns(new CsvConfiguration()); parserMock.Setup(m => m.Read()).Returns(() => data); var reader = new CsvReader(parserMock.Object); reader.Configuration.IsStrictMode = true; reader.Read(); }
public void shouldCallSaveOnRepository() { const string userName = "******"; var password = "******"; var factory = new MockFactory(MockBehavior.Strict); var mock = factory.Create<IUserBusinessLogic>(); var userContextMock = new Mock<IUserContext>(); mock.Setup(x => x.Create(It.Is<User>(y => y.Username == userName))).Returns(new User()); var controller = new CarbonFitness.App.Web.Controllers.UserController(mock.Object, userContextMock.Object); controller.Create(userName, password); factory.VerifyAll(); }
public void CanBindToInstanceFactoryMethodWithParameters() { var factory = new MockFactory(); var module = new InlineModule( m => m.Bind(typeof(IMock)).ToMethod(ctx => factory.Create("foo", 42)) ); using (var kernel = new StandardKernel(module)) { var mock = kernel.Get <IMock>(); Assert.That(mock, Is.Not.Null); Assert.That(mock, Is.InstanceOfType(typeof(ImplB))); } }
public void shouldReturnFalseWhenProvidingWrongPassword() { var username = "******"; var userPassword = "******"; var providedPassword = "******"; var factory = new MockFactory(MockBehavior.Strict); var userRepositoryMock = factory.Create<IUserRepository>(); userRepositoryMock.Setup(x => x.Get(username)).Returns(new User(username, userPassword)); var membershipProvider = new MembershipBusinessLogic(userRepositoryMock.Object); var loginResult = membershipProvider.ValidateUser(username, providedPassword); Assert.That(loginResult, Is.False); }
public void detailsShouldReturnUser() { var factory = new MockFactory(MockBehavior.Strict); var mock = factory.Create<IUserBusinessLogic>(); mock.Setup(x => x.Get(1)).Returns(new User {Username = "******"}); var userBusinessLogic = mock.Object; var controller = new CarbonFitness.App.Web.Controllers.UserController(userBusinessLogic, null); var viewResult = (ViewResult) controller.Details(1); var user = (User) viewResult.ViewData.Model; Assert.That(user, Is.TypeOf(typeof(User))); Assert.AreEqual("kalle", user.Username); }
public void CanBindToParameterlessInstanceFactoryMethod() { var factory = new MockFactory(); var module = new InlineModule( m => m.Bind(typeof(IMock)).ToMethod(ctx => factory.Create()) ); using (var kernel = new StandardKernel(module)) { var mock = kernel.Get<IMock>(); Assert.That(mock, Is.Not.Null); Assert.That(mock, Is.InstanceOfType(typeof(ImplA))); } }
public void GetFieldByNameNoHeaderExceptionTest() { var data = new [] { "1", "2" }; var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); parserMock.Setup(m => m.Read()).Returns(() => data); var reader = new CsvReader(parserMock.Object, new CsvReaderOptions { HasHeaderRecord = false }); reader.Read(); Assert.AreEqual(Convert.ToInt32(data[0]), reader.GetField <int>("One")); }
public void GetFieldByIndexTest() { var data = new [] { "1", "2" }; var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); parserMock.Setup(m => m.Read()).Returns(data); var reader = new CsvReader(parserMock.Object); reader.Read(); Assert.AreEqual(1, reader.GetField <int>(0)); Assert.AreEqual(2, reader.GetField <int>(1)); }
public void GetRecordNoAttributesTest() { var headerData = new[] { "IntColumn", "StringColumn", "GuidColumn", "CustomTypeColumn", }; var recordData = new[] { "1", "string column", Guid.NewGuid().ToString(), "blah", }; var isHeaderRecord = true; var mockFactory = new MockFactory(MockBehavior.Default); var csvParserMock = mockFactory.Create <ICsvParser>(); csvParserMock.Setup(m => m.Configuration).Returns(new CsvConfiguration()); csvParserMock.Setup(m => m.Read()).Returns(() => { if (isHeaderRecord) { isHeaderRecord = false; return(headerData); } return(recordData); }); var csv = new CsvReader(csvParserMock.Object); csv.Configuration.IsStrictMode = false; csv.Read(); var record = csv.GetRecord <TestRecordNoAttributes>(); Assert.AreEqual(Convert.ToInt32(recordData[0]), record.IntColumn); Assert.AreEqual(recordData[1], record.StringColumn); Assert.AreEqual(default(string), record.IgnoredColumn); Assert.AreEqual(default(string), record.TypeConvertedColumn); Assert.AreEqual(default(int), record.FirstColumn); Assert.AreEqual(new Guid(recordData[2]), record.GuidColumn); Assert.AreEqual(default(int), record.NoMatchingFields); Assert.AreEqual(default(TestRecord), record.CustomTypeColumn); }
public void GetRecordsTest() { var headerData = new [] { "IntColumn", "String Column", "GuidColumn", }; var count = -1; var mockFactory = new MockFactory(MockBehavior.Default); var csvParserMock = mockFactory.Create <ICsvParser>(); csvParserMock.Setup(m => m.Configuration).Returns(new CsvConfiguration()); var guid = Guid.NewGuid(); csvParserMock.Setup(m => m.Read()).Returns(() => { count++; if (count == 0) { return(headerData); } if (count > 2) { return(null); } return(new[] { count.ToString(), "string column " + count, guid.ToString() }); }); var csv = new CsvReader(csvParserMock.Object); csv.Configuration.IsStrictMode = false; var records = csv.GetRecords <TestRecord>().ToList(); Assert.AreEqual(2, records.Count); for (var i = 1; i <= records.Count; i++) { var record = records[i - 1]; Assert.AreEqual(i, record.IntColumn); Assert.AreEqual("string column " + i, record.StringColumn); Assert.AreEqual("test", record.TypeConvertedColumn); Assert.AreEqual(i, record.FirstColumn); Assert.AreEqual(guid, record.GuidColumn); } }
public void shouldPassCreatedUserIdToDetails() { var userName = "******"; var password = "******"; var factory = new MockFactory(MockBehavior.Strict); var userContextMock = new Mock<IUserContext>(); var mock = factory.Create<IUserBusinessLogic>(); var createdUser = new User {Username = userName}; mock.Setup(x => x.Create(It.Is<User>(y => y.Username == userName))).Returns(createdUser); var controller = new CarbonFitness.App.Web.Controllers.UserController(mock.Object, userContextMock.Object); var viewResult = (RedirectToRouteResult) controller.Create(userName, password); var idRouteValue = viewResult.RouteValues["id"]; Assert.That(idRouteValue.ToString() == createdUser.Id.ToString(), "Expected id" + createdUser.Id + ", but was:" + idRouteValue); }
public void shouldReturnTrueWhenValidating() { var factory = new MockFactory(MockBehavior.Strict); var userRepositoryMock = factory.Create<IUserRepository>(); var wrongUsername = "******"; var wrongPassword = "******"; var existingUsername = "******"; var existingPassword = "******"; userRepositoryMock.Setup(x => x.Get(existingUsername)).Returns(new User(existingUsername, existingPassword)); userRepositoryMock.Setup(x => x.Get(wrongUsername)).Returns((User) null); var membershipProvider = new MembershipBusinessLogic(userRepositoryMock.Object); var loginSuccessfull = membershipProvider.ValidateUser(existingUsername, existingPassword); var loginFailed = membershipProvider.ValidateUser(wrongUsername, wrongPassword); Assert.That(loginSuccessfull); Assert.That(loginFailed, Is.False); }
public void GetRecordTest() { var headerData = new [] { "IntColumn", "String Column", "GuidColumn", }; var recordData = new [] { "1", "string column", Guid.NewGuid().ToString(), }; var isHeaderRecord = true; var mockFactory = new MockFactory(MockBehavior.Default); var csvParserMock = mockFactory.Create <ICsvParser>(); csvParserMock.Setup(m => m.Configuration).Returns(new CsvConfiguration()); csvParserMock.Setup(m => m.Read()).Returns(() => { if (isHeaderRecord) { isHeaderRecord = false; return(headerData); } return(recordData); }); var csv = new CsvReader(csvParserMock.Object); csv.Read(); var record = csv.GetRecord <TestRecord>(); Assert.AreEqual(Convert.ToInt32(recordData[0]), record.IntColumn); Assert.AreEqual(recordData[1], record.StringColumn); Assert.AreEqual("test", record.TypeConvertedColumn); Assert.AreEqual(Convert.ToInt32(recordData[0]), record.FirstColumn); Assert.AreEqual(new Guid(recordData[2]), record.GuidColumn); }
public void GetFieldByNameTest() { var isHeaderRecord = true; var data1 = new [] { "One", "Two" }; var data2 = new [] { "1", "2" }; var mockFactory = new MockFactory( MockBehavior.Default ); var parserMock = mockFactory.Create<ICsvParser>(); parserMock.Setup( m => m.Read() ).Returns( () => { if( isHeaderRecord ) { isHeaderRecord = false; return data1; } return data2; } ); var reader = new CsvReader( parserMock.Object ); reader.Read(); Assert.AreEqual( Convert.ToInt32( data2[0] ), reader.GetField<int>( "One" ) ); Assert.AreEqual( Convert.ToInt32( data2[1] ), reader.GetField<int>( "Two" ) ); }
public void TryGetFieldEmptyDate() { // DateTimeConverter.IsValid() doesn't work correctly // so we need to test and make sure that the conversion // fails for an emptry string for a date. var data = new[] { " " }; var mockFactory = new MockFactory(MockBehavior.Default); var parserMock = mockFactory.Create <ICsvParser>(); parserMock.Setup(m => m.Configuration).Returns(new CsvConfiguration()); parserMock.Setup(m => m.Read()).Returns(data); var reader = new CsvReader(parserMock.Object); reader.Read(); DateTime field; var got = reader.TryGetField(0, out field); Assert.IsFalse(got); Assert.AreEqual(DateTime.MinValue, field); }
public void shouldReportErrorWhenNoIngredientFound() { var mockFactory = new MockFactory(MockBehavior.Loose); var userContextMock = GetSetuppedUserContextMock(mockFactory); var ingredientName = "afafafafafafafa"; var userIngredientBusinessLogicMock = mockFactory.Create<IUserIngredientBusinessLogic>(); userIngredientBusinessLogicMock.Setup(x => x.GetUserIngredients(It.IsAny<User>(), It.IsAny<DateTime>())).Returns(new[] {new UserIngredient()}); userIngredientBusinessLogicMock.Setup(x => x.AddUserIngredient(It.IsAny<User>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<DateTime>())) .Throws(new NoIngredientFoundException(ingredientName)); var foodController = new CarbonFitness.App.Web.Controllers.FoodController(userIngredientBusinessLogicMock.Object, new Mock<IRDIProxy>().Object, userContextMock.Object); foodController.Input(new InputFoodModel {Ingredient = ingredientName, Measure = 10}); //var model = testController(x => x.Input(new InputFoodModel()), userIngredientBusinessLogicMock, userContextMock); var errormessage = getErrormessage(foodController, "Ingredient"); Assert.That(errormessage.Contains(ingredientName)); Assert.That(errormessage, Is.EqualTo(FoodConstant.NoIngredientFoundMessage + ingredientName)); }
public void SetUp() { _factory = new MockFactory(MockBehavior.Strict); _settings = _factory.Create<IVimGlobalSettings>(); _textSearch = _factory.Create<ITextSearchService>(); _searchRaw = new SearchService(_textSearch.Object, _settings.Object); _search = _searchRaw; }
public void TestInitialize() { mocks = new MockFactory(MockBehavior.Strict); mockSerialiser = mocks.Create<ISerialiser>(); mockRestClient = mocks.Create<IRestClient>(); service = new MessagingService(mockRestClient.Object, mockSerialiser.Object, false); }
public void Create(params string[] lines) { _view = Utils.EditorUtil.CreateView(lines); _view.Caret.MoveTo(new SnapshotPoint(_view.TextSnapshot, 0)); _buffer = _view.TextBuffer; _factory = new MockFactory(MockBehavior.Strict); _host = _factory.Create<IVimHost>(); _jumpList = _factory.Create<IJumpList>(); _editorOpts = _factory.Create<IEditorOperations>(); _settings = _factory.Create<IVimLocalSettings>(); _globalSettings = _factory.Create<IVimGlobalSettings>(); _outlining = _factory.Create<IOutliningManager>(); _globalSettings.SetupGet(x => x.ShiftWidth).Returns(2); _settings.SetupGet(x => x.GlobalSettings).Returns(_globalSettings.Object); _undoRedoOperations = _factory.Create<IUndoRedoOperations>(); _operationsRaw = new OperationsImpl(_view, _editorOpts.Object, _outlining.Object, _host.Object, _jumpList.Object,_settings.Object, _undoRedoOperations.Object); _operations = _operationsRaw; }
public void TestInitialize() { mocks = new MockFactory(MockBehavior.Strict); mockHttpWebResponse = mocks.Create<IHttpWebResponseAdapter>(); helper = new HttpResponseHelper(); }
public virtual void Setup() { Mockery = new MockFactory(MockBehavior.Default); Selenium = Mockery.Create<ISelenium>(); }
public void shouldRemoveUserIngredient() { var mockFactory = new MockFactory(MockBehavior.Loose); var userContextMock = GetSetuppedUserContextMock(mockFactory); var userIngredientBusinessLogicMock = mockFactory.Create<IUserIngredientBusinessLogic>(); userIngredientBusinessLogicMock.Setup(x => x.DeleteUserIngredient(It.IsAny<User>(), It.IsAny<int>(), It.IsAny<DateTime>())); var foodController = new CarbonFitness.App.Web.Controllers.FoodController(userIngredientBusinessLogicMock.Object, new Mock<IRDIProxy>().Object, userContextMock.Object); foodController.DeleteUserIngredient(3, DateTime.Now); userIngredientBusinessLogicMock.VerifyAll(); }
private Mock<IUserIngredientBusinessLogic> GetSetuppedUserIngredientBusinessLogicMock(MockFactory mockFactory) { var userIngredientBusinessLogicMock = mockFactory.Create<IUserIngredientBusinessLogic>(); var returnedUserIngredients = new[] {new UserIngredient {Date = DateTime.Now}, new UserIngredient {Date = DateTime.Now}}; userIngredientBusinessLogicMock.Setup(x => x.GetUserIngredients(It.IsAny<User>(), It.Is<DateTime>(y => y.ToShortDateString() == DateTime.Now.ToShortDateString()))).Returns(returnedUserIngredients); return userIngredientBusinessLogicMock; }
public void SetUp() { mockFactory = new MockFactory(MockBehavior.Strict); processStarter = mockFactory.Create<IProcessStarter>(); configuration = mockFactory.Create<DotNetProjectConfiguration>(); configSelector = mockFactory.Create<ConfigurationSelector>(); monitor = mockFactory.Create<IProgressMonitor>(); monitorLog = mockFactory.Create<TextWriter>(); booLanguageBinding = new BooLanguageBinding(processStarter.Object); }
private void Create(params string[] lines) { _textView = EditorUtil.CreateView(lines); _factory = new MockFactory(MockBehavior.Strict); _searchService = _factory.Create<ISearchService>(); _nav = _factory.Create<ITextStructureNavigator>(); _globalSettings = MockObjectFactory.CreateGlobalSettings(ignoreCase: true); _settings = MockObjectFactory.CreateLocalSettings(_globalSettings.Object); _outlining = new Mock<IOutliningManager>(MockBehavior.Strict); _outlining.Setup(x => x.ExpandAll(It.IsAny<SnapshotSpan>(), It.IsAny<Predicate<ICollapsed>>())).Returns<IEnumerable<ICollapsed>>(null); _searchRaw = new IncrementalSearch( _textView, _outlining.Object, _settings.Object, _nav.Object, _searchService.Object); _search = _searchRaw; }
private Mock<IUserContext> GetSetuppedUserContextMock(MockFactory mockFactory) { var userContextMock = mockFactory.Create<IUserContext>(); userContextMock.Setup(x => x.User).Returns(new User {Username = "******"}); return userContextMock; }