예제 #1
0
        public void TestXmlNoModClass()
        {
            Mockery mocks = new Mockery();
            IInputContext context = mocks.NewMock<IInputContext>();
            IDnaDataReader mockedReader = mocks.NewMock<IDnaDataReader>();
            Stub.On(context).Method("CreateDnaDataReader").Will(Return.Value(mockedReader));
            Stub.On(mockedReader).Method("Execute");
            Stub.On(mockedReader).Method("Dispose");
            IAction mockReaderResults = new MockedReaderResults(new object[] { true, false });
            Stub.On(mockedReader).Method("Read").Will(mockReaderResults);

            // Check Stored Procedure is called as expected.
            Expect.Never.On(mockedReader).Method("AddParameter").With("modclassid");

            Stub.On(mockedReader).Method("GetInt32NullAsZero").With("reasonid").Will(Return.Value(6));
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("displayname").Will(Return.Value("DisplayName"));
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("emailname").Will(Return.Value("EmailName"));
            Stub.On(mockedReader).Method("GetTinyIntAsInt").With("editorsonly").Will(Return.Value(0));

            ModerationReasons modReasons = new ModerationReasons(context);
            modReasons.GenerateXml(0);

            //Check XML.is as expected.
            XmlNode node = modReasons.RootElement.SelectSingleNode(@"MOD-REASONS");
            Assert.IsNotNull(node, "ModerationReasons Element Found");
            Assert.IsNull(modReasons.RootElement.SelectSingleNode(@"MOD-REASONS/@MODCLASSID"), "Moderation Class Id");
            Assert.IsNotNull(modReasons.RootElement.SelectSingleNode(@"MOD-REASONS/MOD-REASON[@DISPLAYNAME='DisplayName']"), "Displayname");
            Assert.IsNotNull(modReasons.RootElement.SelectSingleNode(@"MOD-REASONS/MOD-REASON[@EMAILNAME='EmailName']"), "Emailname");
            Assert.IsNotNull(modReasons.RootElement.SelectSingleNode(@"MOD-REASONS/MOD-REASON[@EDITORSONLY='0']"), "Editors Only");


            mocks.VerifyAllExpectationsHaveBeenMet();
        }
 public void beforTest()
 {
     mockery = new Mockery();
     view = mockery.NewMock<ITrackView>();
     dao = mockery.NewMock<ITrackDao>();
     presenter = new TrackPresenter(view, dao);
 }
예제 #3
0
		public void TestGetHandlerFor()
		{
			Mockery mocks;
			IOTAProject mockProject;
			IUser mockUser;
			IGenerator mockGenerator;
			mocks = new Mockery();
			mockProject = mocks.NewMock<IOTAProject>();
			mockUser = mocks.NewMock<IUser>();
			mockGenerator = mocks.NewMock<IGenerator>();
			//TODO: use Mock objects.
			string fileName = Path.Combine(Path.GetTempPath(), "test.dproj");
			Expect.AtLeast(3).On(mockProject).GetProperty("FileName").
				Will(Return.Value(fileName));
			Expect.Once.On(mockProject).Method("Save").WithAnyArguments().Will(Return.Value(true));
			Expect.Once.On(mockProject).Method("AddFile").WithAnyArguments().Will(Return.Value(null));
			Expect.Once.On(mockUser).Method("ProvideKeyFile").Will(Return.Value(null));
			Expect.Once.On(mockGenerator).Method("GenerateKey").WithAnyArguments().Will(Return.Value(true));
			IHandler handler = HandlerFactory.GetHandlerFor(mockProject);
			Assert.IsTrue(handler is Manner20UnsignedHandler);
			(handler as Manner20UnsignedHandler).User = mockUser;
			(handler as Manner20UnsignedHandler).Generator = mockGenerator;
			handler.Handle();
			IHandler handler2 = HandlerFactory.GetHandlerFor(mockProject);
			Assert.IsTrue(handler2 is Manner20SignedHandler);
			mocks.VerifyAllExpectationsHaveBeenMet();
		}
예제 #4
0
        public void ShouldCreateInstanceWithCacheKeyAndInvokeDynamicFactoryTest()
        {
            Mockery mockery;
            MockProxyFactory factory;
            IMockObject objectContract;
            MockProxyFactory.IInvokeDynamicFactory mockInvokeDynamicFactory;
            IDynamicInvocation mockDynamicInvocation;
            MethodInfo invokedMethodInfo;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock<IDynamicInvocation>();
            mockInvokeDynamicFactory = mockery.NewMock<MockProxyFactory.IInvokeDynamicFactory>();

            invokedMethodInfo = (MethodInfo)MemberInfoProxy<IDisposable>.GetLastMemberInfo(exec => exec.Dispose());

            Expect.Once.On(mockInvokeDynamicFactory).Method("GetDynamicInvoker").With("myCacheKey", typeof(IMockObject)).Will(Return.Value(mockDynamicInvocation));

            factory = new MockProxyFactory();

            Assert.IsNotNull(factory);

            objectContract = factory.CreateInstance("myCacheKey", mockInvokeDynamicFactory);
            Assert.IsNotNull(objectContract);

            factory.Dispose();

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
예제 #5
0
        public void EnsureValidH2G2IDSucceedsToCreate()
        {
            // Create a mockery of the input context
            Mockery mockery = new Mockery();
            IInputContext mockedContext = mockery.NewMock<IInputContext>();

            IDnaDataReader mockedReader = mockery.NewMock<IDnaDataReader>();
            Stub.On(mockedReader).Method("AddParameter").Will(Return.Value(mockedReader));
            Stub.On(mockedReader).Method("Execute").Will(Return.Value(mockedReader));
            Stub.On(mockedReader).GetProperty("HasRows").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Read").Will(Return.Value(true));
            
            // Set the expiry date to be 1 minute from now
            Stub.On(mockedReader).Method("GetInt32").With("seconds").Will(Return.Value(60));
            Stub.On(mockedReader).Method("Dispose").Will(Return.Value(null));

            Stub.On(mockedContext).Method("CreateDnaDataReader").With("cachegetarticleinfo").Will(Return.Value(mockedReader));

            // Return false for now as it's bloody inpossible to test methods that use ref params!!!
            Stub.On(mockedContext).Method("FileCacheGetItem").Will(Return.Value(false));

            // Now create the setup object and create the guideentry
            GuideEntrySetup setup = new GuideEntrySetup(388217);
            GuideEntry testEntry = new GuideEntry(mockedContext, setup);

            // Test the initialisation code.
            Assert.IsTrue(testEntry.Initialise(), "Valid h2g2id should return true!");
        }
예제 #6
0
        public void FindElementTwoBy()
        {
            var mocks = new Mockery();
            var driver = mocks.NewMock<IAllDriver>();

            var elem1 = mocks.NewMock<IAllElement>();
            var elem2 = mocks.NewMock<IAllElement>();
            var elem3 = mocks.NewMock<IAllElement>();
            var elems12 = new List<IWebElement> { elem1, elem2 }.AsReadOnly();
            var elems23 = new List<IWebElement> { elem2, elem3 }.AsReadOnly();

            Expect.AtLeastOnce.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems12));
            Expect.AtLeastOnce.On(driver).Method("FindElementsByName").With("photo").Will(Return.Value(elems23));

            var by = new ByAll(By.Name("cheese"), By.Name("photo"));

            // findElement
            Assert.That(by.FindElement(driver), Is.EqualTo(elem2));

            //findElements
            var result = by.FindElements(driver);
            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result[0], Is.EqualTo(elem2));

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
예제 #7
0
 public void SetUp()
 {
     mocks = new Mockery();
     mockDriver = mocks.NewMock<ISearchContext>();
     mockElement = mocks.NewMock<IWebElement>();
     mockExplicitDriver = mocks.NewMock<IWebDriver>();
 }
        public void TestPersist()
        {
            Mockery mocks = new Mockery();

            //Crate mocks
            IUserGateway mockGateway = mocks.NewMock<IUserGateway>();
            IUserValidator mockValidator = mocks.NewMock<IUserValidator>();

            //Create user
            User user = new User();

            //Expectations
            using(mocks.Ordered)
            {
                Expect.Once.On(mockValidator).Method("Validate").With(user).Will(Return.Value(true));
                Expect.Once.On(mockGateway).Method("Persist").With(user).Will(Return.Value(true));
            }

            //Assign gateway
            user.Gateway = mockGateway;

            //Test method
            Assert.AreEqual(true, user.Persist(mockValidator));

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
 public void beforTest()
 {
     mockery = new Mockery();
     view = mockery.NewMock<IPlaylistCreatorView>();
     task = mockery.NewMock<IPlaylistCreatorTask>();
     presenter = new PlaylistCreatorPresenter(view, task);
 }
        //TODO: Talk with Mark H to understand the purpose of this test.
        //Why is this relevent specifically to ContactFormListBuilder for example?
        //Is it not a more generic unit test for base functionality?
        public void GivenCallingProcessInputParametersShouldSetSkipAndShowVariables()
        {
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            ISite mockedSite = mock.NewMock<ISite>();

            Stub.On(mockedSite).GetProperty("SiteID").Will(Return.Value(1));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(mockedSite));

            ContactFormListBuilder_Accessor privateAccessor = new ContactFormListBuilder_Accessor(mockedInputContext);

            int expectedShow = 20;
            int expectedSkip = 10;
            int expectedSiteID = 66;

            Stub.On(mockedInputContext).Method("DoesParamExist").With("skip", "Items to skip").Will(Return.Value(true));
            Stub.On(mockedInputContext).Method("DoesParamExist").With("show", "Items to show").Will(Return.Value(true));
            Stub.On(mockedInputContext).Method("GetParamIntOrZero").With("skip", "Items to skip").Will(Return.Value(expectedSkip));
            Stub.On(mockedInputContext).Method("GetParamIntOrZero").With("show", "Items to show").Will(Return.Value(expectedShow));
            Stub.On(mockedInputContext).Method("GetParamIntOrZero").With("dnasiteid", "The specified site").Will(Return.Value(expectedSiteID));

            privateAccessor.ProcessInputParameters();

            Assert.AreEqual(privateAccessor.show, expectedShow);
            Assert.AreEqual(privateAccessor.skip, expectedSkip);
            Assert.AreEqual(privateAccessor.requestedSiteID, expectedSiteID);
        }
예제 #11
0
        public void TestGetCommentsListForUser6()
        {
            Console.WriteLine("Before CommentLists - TestGetCommentsListForUser6");
            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");
            ISite site = mock.NewMock<ISite>();
            //Stub.On(site).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            User user = new User(mockedInputContext);
            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(site));

            // Create the stored procedure reader for the CommentList object
            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            using (IDnaDataReader reader = context.CreateDnaDataReader("getusercommentsstats"))
            {
                using (IDnaDataReader reader2 = context.CreateDnaDataReader("fetchgroupsandmembers"))
                {
                    Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("getusercommentsstats").Will(Return.Value(reader));
                    Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("fetchgroupsandmembers").Will(Return.Value(reader2));

                    // Create a new CommentsList object and get the list of comments
                    CommentsList testCommentsList = new CommentsList(mockedInputContext);
                    Assert.IsTrue(testCommentsList.CreateRecentCommentsList(6, 1, 0, 20));
                }
            }
            Console.WriteLine("After CommentLists - TestGetCommentsListForUser6");
        }
예제 #12
0
        public void GivenRequestToContactFormListPageShouldSetSkipAndShowVariablesInXML()
        {
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            ISite mockedSite = mock.NewMock<ISite>();

            Stub.On(mockedSite).GetProperty("SiteID").Will(Return.Value(1));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(mockedSite));

            IDnaDataReader mockedReader = mock.NewMock<IDnaDataReader>();
            Stub.On(mockedReader).Method("AddParameter");
            Stub.On(mockedReader).Method("Execute");
            Stub.On(mockedReader).GetProperty("HasRows").Will(Return.Value(false));
            Stub.On(mockedReader).Method("Dispose");
            Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("getcontactformslist").Will(Return.Value(mockedReader));

            ContactFormListBuilder contactFormBuilder = new ContactFormListBuilder(mockedInputContext);

            int expectedShow = 200;
            int expectedSkip = 1000;
            int expectedSiteID = 66;

            Stub.On(mockedInputContext).Method("DoesParamExist").With("action", "process action param").Will(Return.Value(false));
            Stub.On(mockedInputContext).Method("DoesParamExist").With("dnaskip", "Items to skip").Will(Return.Value(true));
            Stub.On(mockedInputContext).Method("DoesParamExist").With("dnashow", "Items to show").Will(Return.Value(true));
            Stub.On(mockedInputContext).Method("GetParamIntOrZero").With("dnaskip", "Items to skip").Will(Return.Value(expectedSkip));
            Stub.On(mockedInputContext).Method("GetParamIntOrZero").With("dnashow", "Items to show").Will(Return.Value(expectedShow));
            Stub.On(mockedInputContext).Method("GetParamIntOrZero").With("dnasiteid", "The specified site").Will(Return.Value(expectedSiteID));

            XmlNode requestResponce = contactFormBuilder.GetContactFormsAsXml();

            Assert.AreEqual(expectedShow, Int32.Parse(requestResponce.SelectSingleNode("@SHOW").Value));
            Assert.AreEqual(expectedSkip, Int32.Parse(requestResponce.SelectSingleNode("@SKIP").Value));
            Assert.AreEqual(expectedSiteID, Int32.Parse(requestResponce.SelectSingleNode("@REQUESTEDSITEID").Value));
        }
        public void TestEmailSendMailOrSystemMessage()
        {
            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext context = DnaMockery.CreateDatabaseInputContext();

            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");

            // Create a mocked site for the context
            ISite mockedSite = mock.NewMock<ISite>();
            //Stub.On(mockedSite).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(mockedSite).GetProperty("SiteID").Will(Return.Value(1));
            Stub.On(mockedSite).GetProperty("SiteName").Will(Return.Value("h2g2"));
            Stub.On(mockedSite).GetProperty("ModClassID").Will(Return.Value(1));

            Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(mockedSite));

            IUser mockedUser = mock.NewMock<IUser>();
            Stub.On(mockedUser).GetProperty("UserID").Will(Return.Value(1090558354));

            Stub.On(context).GetProperty("ViewingUser").Will(Return.Value(mockedUser));
            Stub.On(context).Method("GetSiteRoot").Will(Return.Value("dnadev.national.core.bbc.co.uk:8081/dna/"));
            Stub.On(context).Method("SendMailOrSystemMessage");

            MessageBoardStatistics mbStats = new MessageBoardStatistics(context);
            mbStats.SendMessageBoardStatsEmail((new DateTime(2008, 1, 1)), "*****@*****.**", "*****@*****.**" );


        }
예제 #14
0
        public void SetUp()
        {
            _mock = new Mockery();
            _site = _mock.NewMock<ISite>();
            Stub.On(_site).GetProperty("DefaultSkin").Will(Return.Value(SITE_DEFAULT_SKIN));
            Stub.On(_site).Method("DoesSkinExist").With(SITE_DEFAULT_SKIN).Will(Return.Value(true));
            Stub.On(_site).Method("DoesSkinExist").With(INVALID_SKIN).Will(Return.Value(false));
            Stub.On(_site).Method("DoesSkinExist").With(USER_PREFERRED_SKIN).Will(Return.Value(true));
            Stub.On(_site).Method("DoesSkinExist").With(Is.Null).Will(Return.Value(false));
            Stub.On(_site).Method("DoesSkinExist").With(REQUESTED_SKIN).Will(Return.Value(true));
            Stub.On(_site).Method("DoesSkinExist").With(FILTER_DERIVED_SKIN).Will(Return.Value(true));
            Stub.On(_site).Method("DoesSkinExist").With("xml").Will(Return.Value(true));
            Stub.On(_site).GetProperty("SkinSet").Will(Return.Value("vanilla"));
            
            _user = _mock.NewMock<IUser>();

            _inputContext = _mock.NewMock<IInputContext>();
            Stub.On(_inputContext).GetProperty("CurrentSite").Will(Return.Value(_site));

            _outputContext = _mock.NewMock<IOutputContext>();
            Stub.On(_outputContext).Method("VerifySkinFileExists").Will(Return.Value(true));
    
            _skinSelector = new SkinSelector();
           
            _request = _mock.NewMock<IRequest>();
        }
예제 #15
0
 public void Initialize()
 {
     _mockery = new Mockery();
     _view = _mockery.NewMock<IEmployeeView>();
     _service = _mockery.NewMock<IEmployeeService>();
     _model = new EmployeeModel();
     _presenter = new EmployeePresenter(_view, _model, _service);
 }
 public void beforTest()
 {
     mocks = new Mockery();
     view = mocks.NewMock<IPlaylistSelectorView>();
     task = mocks.NewMock<IPlaylistSelectorTask>();
     lookupList = mocks.NewMock<ILookupList>();
     presenter = new PlaylistSelectorPresenter(view, task);
 }
 public void Setup()
 {
     mocks = new Mockery();
     mockDriver = mocks.NewMock<IWebDriver>();
     mockElement = mocks.NewMock<IWebElement>();
     mockNavigation = mocks.NewMock<INavigation>();
     log = new StringBuilder();
 }
 public void SetUp()
 {
     mockery = new Mockery();
     dependencySessionContainer = mockery.NewMock<ISessionContainer>();
     dependencyDb = mockery.NewMock<IWorkTimeAccountingPlatformDAO>();
     dependencySessionIdProvider = mockery.NewMock<ISessionIdProvider>();
     testee = new CommunicationService(dependencySessionContainer, dependencyDb, dependencySessionIdProvider);
 }
 public void beforTest()
 {
     mockery = new Mockery();
     view = mockery.NewMock<ITrackListingView>();
     task = mockery.NewMock<ITrackListingTask>();
     presenter = new TrackListingPresenter(view, task);
     stateBag = new StateBag();
 }
 public void SetUp()
 {
     m_mockery = new Mockery();
     m_extensionA = m_mockery.NewMock<IMockExtensionTypeA>();
     m_extensionB = m_mockery.NewMock<IMockExtensionTypeB>();
     m_extensionC = new MockExtensionTypeC();
     m_extensionD = m_mockery.NewMock<IMockExtensionTypeD>();
 }
예제 #21
0
        public void ShouldCreateParameterTest()
        {
            Mockery mockery;
            AdoNetDataSource dataSource;
            IConnectionFactory mockConnectionFactory;
            IDbConnection mockDbConnection;
            IDbCommand mockDbCommand;

            IDataParameter p;
            IDbDataParameter mockDbParameter;

            mockery = new Mockery();
            mockConnectionFactory = mockery.NewMock<IConnectionFactory>();
            mockDbConnection = mockery.NewMock<IDbConnection>();
            mockDbCommand = mockery.NewMock<IDbCommand>();
            mockDbParameter = mockery.NewMock<IDbDataParameter>();

            Expect.Once.On(mockConnectionFactory).Method("GetConnection").Will(Return.Value(mockDbConnection));
            Expect.Once.On(mockDbConnection).Method("CreateCommand").Will(Return.Value(mockDbCommand));
            Expect.Once.On(mockDbConnection).Method("Dispose");
            Expect.Once.On(mockDbCommand).Method("CreateParameter").Will(Return.Value(mockDbParameter));
            Expect.Once.On(mockDbCommand).Method("Dispose");

            Expect.Once.On(mockDbParameter).SetProperty("ParameterName").To("@bob");
            Expect.Once.On(mockDbParameter).SetProperty("Size").To(1);
            Expect.Once.On(mockDbParameter).SetProperty("Value").To("test");
            Expect.Once.On(mockDbParameter).SetProperty("Direction").To(ParameterDirection.Input);
            Expect.Once.On(mockDbParameter).SetProperty("DbType").To(DbType.String);
            Expect.Once.On(mockDbParameter).SetProperty("Precision").To((byte)2);
            Expect.Once.On(mockDbParameter).SetProperty("Scale").To((byte)3);
            //Expect.Once.On(mockDbParameter).SetProperty("IsNullable").To(true);

            Expect.Once.On(mockDbParameter).GetProperty("ParameterName").Will(Return.Value("@bob"));
            Expect.Once.On(mockDbParameter).GetProperty("Size").Will(Return.Value(1));
            Expect.Once.On(mockDbParameter).GetProperty("Value").Will(Return.Value("test"));
            Expect.Once.On(mockDbParameter).GetProperty("Direction").Will(Return.Value(ParameterDirection.Input));
            Expect.Once.On(mockDbParameter).GetProperty("DbType").Will(Return.Value(DbType.String));
            Expect.Once.On(mockDbParameter).GetProperty("Precision").Will(Return.Value((byte)2));
            Expect.Once.On(mockDbParameter).GetProperty("Scale").Will(Return.Value((byte)3));
            //Expect.Once.On(mockDbParameter).GetProperty("IsNullable").Will(Return.Value(true));

            dataSource = new AdoNetDataSource(MOCK_CONNECTION_STRING, mockConnectionFactory);

            p = dataSource.CreateParameter(null, ParameterDirection.Input, DbType.String, 1, 2, 3, true, "@bob", "test");

            Assert.IsNotNull(p);

            Assert.AreEqual(ParameterDirection.Input, p.Direction);
            Assert.AreEqual("@bob", p.ParameterName);
            Assert.AreEqual("test", p.Value);
            Assert.AreEqual(1, ((IDbDataParameter)p).Size);
            Assert.AreEqual(DbType.String, p.DbType);
            Assert.AreEqual((byte)2, ((IDbDataParameter)p).Precision);
            Assert.AreEqual((byte)3, ((IDbDataParameter)p).Scale);
            //Assert.AreEqual(true, ((IDbDataParameter)p).IsNullable);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
예제 #22
0
        public void UseRedirectParameterTest()
        {

            Console.WriteLine("Before UseRedirectParameterTest");
            Mockery mock = new Mockery();
            IUser viewingUser = mock.NewMock<IUser>();
            Stub.On(viewingUser).GetProperty("UserLoggedIn").Will(Return.Value(true));
            Stub.On(viewingUser).GetProperty("Email").Will(Return.Value("*****@*****.**"));
            Stub.On(viewingUser).GetProperty("IsEditor").Will(Return.Value(false));
            Stub.On(viewingUser).GetProperty("IsSuperUser").Will(Return.Value(false));
            Stub.On(viewingUser).GetProperty("IsBanned").Will(Return.Value(false));

            ISite site = mock.NewMock<ISite>();
            Stub.On(site).GetProperty("IsEmergencyClosed").Will(Return.Value(false));
            Stub.On(site).Method("IsSiteScheduledClosed").Will(Return.Value(false));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            Stub.On(context).GetProperty("ViewingUser").Will(Return.Value(viewingUser));
            Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(site));

            DnaMockery.MockTryGetParamString(context,"dnauid", "this is some unique id blah de blah blah2");
            //Stub.On(context).Method("TryGetParamString").WithAnyArguments().Will(new TryGetParamStringAction("dnauid","this is some unique id blah de blah blah2"));
            Stub.On(context).Method("DoesParamExist").With(Is.EqualTo("dnauid"), Is.Anything).Will(Return.Value(true));

            DnaMockery.MockTryGetParamString(context,"dnahostpageurl", "http://www.bbc.co.uk/dna/something");
            //Stub.On(context).Method("TryGetParamString").With("dnahostpageurl").Will(new TryGetParamStringAction("dnahostpageurl","http://www.bbc.co.uk/dna/something"));
            Stub.On(context).Method("DoesParamExist").With(Is.EqualTo("dnahostpageurl"), Is.Anything).Will(Return.Value(true));

            DnaMockery.MockTryGetParamString(context,"dnainitialtitle", "newtitle");
            //Stub.On(context).Method("TryGetParamString").With("dnainitialtitle").Will(new TryGetParamStringAction("dnainitialtitle", "newtitle"));
            Stub.On(context).Method("DoesParamExist").With(Is.EqualTo("dnainitialtitle"), Is.Anything).Will(Return.Value(true));

            Stub.On(context).Method("DoesParamExist").With(Is.EqualTo("dnaerrortype"),Is.Anything).Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With(Is.EqualTo("moduserid"), Is.Anything).Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With(Is.EqualTo("dnainitialmodstatus"), Is.Anything).Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With(Is.EqualTo("dnaforumclosedate"), Is.Anything).Will(Return.Value(false));
            Stub.On(context).Method("DoesParamExist").With(Is.EqualTo("dnaforumduration"), Is.Anything).Will(Return.Value(false));

            Stub.On(context).Method("GetParamIntOrZero").With(Is.EqualTo("dnafrom"), Is.Anything).Will(Return.Value(0));
            Stub.On(context).Method("GetParamIntOrZero").With(Is.EqualTo("dnato"), Is.Anything).Will(Return.Value(0));
            Stub.On(context).Method("GetParamIntOrZero").With(Is.EqualTo("dnashow"), Is.Anything).Will(Return.Value(0));

            
            
            Stub.On(context).Method("GetSiteOptionValueInt").With("CommentForum","DefaultShow").Will(Return.Value(20));
            //inputContext.InitialiseFromFile(@"../../testredirectparams.txt", @"../../userdave.txt");

            CommentBoxForum forum = new CommentBoxForum(context);
            forum.ProcessRequest();


            string forumXml = forum.RootElement.InnerXml;
            DnaXmlValidator validator = new DnaXmlValidator(forumXml, "CommentBox.xsd");
            validator.Validate();
            Console.WriteLine("After UseRedirectParameterTest");
        }
예제 #23
0
        public void Setup()
        {
            m_Mockery = new Mockery();

            m_FileSystem = m_Mockery.NewMock<IFileSystem>();
            m_ClipBoardHelper = m_Mockery.NewMock<IClipBoardHelper>();
            m_ResultViewHelper = m_Mockery.NewMock<IResultViewHelper>();
            m_DetailsTextViewHelper = m_Mockery.NewMock<ITextViewHelper>();
            m_ExportHelper = m_Mockery.NewMock<IExporter>();
            Expect.Once.On(m_ResultViewHelper).EventAdd("SelectionChanged", Is.Anything);
            m_GeneratorController = new GeneratorController(m_FileSystem, m_ResultViewHelper, m_ClipBoardHelper, m_DetailsTextViewHelper);
        }
예제 #24
0
        public void FindElementsOneBy()
        {
            Mockery mock = new Mockery();
            IAllDriver driver = mock.NewMock<IAllDriver>();
            IAllElement elem1 = mock.NewMock<IAllElement>();
            IAllElement elem2 = mock.NewMock<IAllElement>();
            var elems12 = new List<IWebElement>() { elem1, elem2 }.AsReadOnly();
            Expect.Once.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems12));

            ByChained by = new ByChained(By.Name("cheese"));
            Assert.AreEqual(by.FindElements(driver), elems12);
            mock.VerifyAllExpectationsHaveBeenMet();
        }
예제 #25
0
        public void SetUp()
        {
            // Create the mockery object
            _mock = new Mockery();

            // Now create a mocked DataReader. This will be returned by the mocked input context method CreateDnaDataReader
            _mockedDataReader = _mock.NewMock<IDnaDataReader>();
            _mockedDiagnostics = _mock.NewMock<IDnaDiagnostics>();
            Stub.On(_mockedDiagnostics).Method("WriteWarningToLog").Will(Return.Value(null));

            // Ensure the Statistics object is initialised
            Statistics.ResetCounters();
        }
예제 #26
0
        public void Setup()
        {
            m_Mockery = new Mockery();
            m_Document = new Document();
            m_TextViewHelper = m_Mockery.NewMock<ITextViewHelper>();
            m_FileSystem = m_Mockery.NewMock<IFileSystem>();
            m_FileDialogHelper = m_Mockery.NewMock<IFileDialogHelper>();
            m_WarningViewHelper = m_Mockery.NewMock<IWarningViewHelper>();

            Expect.Once.On(m_TextViewHelper).EventAdd("BufferChanged", Is.Anything);
            Expect.Once.On(m_WarningViewHelper).EventAdd("WarningActivated", Is.Anything);
            m_DocumentController = new DocumentController(m_WarningViewHelper, m_FileSystem, m_FileDialogHelper, m_TextViewHelper, m_Document);
        }
예제 #27
0
		public void TestUrlSkinName()
		{
            Console.WriteLine("After TestUrlSkinName");
            Mockery mock = new Mockery();
			IInputContext context = mock.NewMock<IInputContext>();
			XmlDocument siteconfig = new XmlDocument();
			siteconfig.LoadXml("<SITECONFIG />");
			ISite site = mock.NewMock<ISite>();
			Stub.On(site).GetProperty("Config").Will(Return.Value(String.Empty));

			User user = new User(context);
            Stub.On(context).Method("IsPreviewMode").Will(Return.Value(false));
			Stub.On(context).GetProperty("ViewingUser").Will(Return.Value(user));
			Stub.On(context).GetProperty("UserAgent").Will(Return.Value("Mozilla+blah+blah"));
			Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(site));
			Stub.On(context).Method("DoesParamExist").With(Is.EqualTo("_sk"), Is.Anything).Will(Return.Value(true));
			Stub.On(context).Method("GetParamStringOrEmpty").With(Is.EqualTo("_sk"), Is.Anything).Will(Return.Value("randomskin"));

			WholePage page = new WholePage(context);
			page.InitialisePage("TEST");
			Assert.IsNotNull(page.RootElement);
			Assert.AreEqual(page.RootElement.FirstChild.Name, "H2G2");
			XmlNodeList nodes = page.RootElement.SelectNodes("H2G2/VIEWING-USER");
			Assert.IsNotNull(nodes);
			Assert.AreEqual(nodes.Count, 1, "Only expecting one Viewing User element");
			nodes = page.RootElement.SelectNodes("H2G2/URLSKINNAME");
			Assert.IsNotNull(nodes);
			Assert.AreEqual(nodes.Count, 1, "Only expecting one URLSKINNAME element");
			XmlNode node = nodes[0];
			Assert.AreEqual(node.InnerText, "randomskin", "Expected 'randomskin' for the skin name in the URLSKINNAME element");

			context = mock.NewMock<IInputContext>();
            Stub.On(context).Method("IsPreviewMode").Will(Return.Value(false));
			Stub.On(context).GetProperty("ViewingUser").Will(Return.Value(user));
			Stub.On(context).GetProperty("UserAgent").Will(Return.Value("Mozilla+blah+blah"));
			Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(site));
			Stub.On(context).Method("DoesParamExist").With(Is.EqualTo("_sk"), Is.Anything).Will(Return.Value(false));
			Stub.On(context).Method("GetParamStringOrEmpty").With(Is.EqualTo("_sk"), Is.Anything).Will(Return.Value(""));
			page = new WholePage(context);
			page.InitialisePage("TEST");
			Assert.IsNotNull(page.RootElement);
			Assert.AreEqual(page.RootElement.FirstChild.Name, "H2G2");
			nodes = page.RootElement.SelectNodes("H2G2/VIEWING-USER");
			Assert.IsNotNull(nodes);
			Assert.AreEqual(nodes.Count, 1, "Only expecting one Viewing User element");
			nodes = page.RootElement.SelectNodes("H2G2/URLSKINNAME");
			Assert.IsNotNull(nodes);
			Assert.AreEqual(nodes.Count, 0, "Not expecting one URLSKINNAME element");
            Console.WriteLine("After TestUrlSkinName");
        }
        public void ShouldAddEventToScenario()
        {
            //Given
            Mockery mocks = new Mockery();
            IGiven aGiven = (IGiven)mocks.NewMock<IGiven>();
            IEvent evt = mocks.NewMock<IEvent>();
            Scenario.Scenario  scenario = new MyScenario();

            //When
            scenario.Given("a given", aGiven).When("an event", evt);

            //Then
            Assert.IsNotNull (scenario.Event);
        }
예제 #29
0
        public void TestCloning()
        {
            //Generated classes have built in Clone() methods. Verify they check out
            _mocks = new Mockery();
            var conn = _mocks.NewMock<IServerConnection>();
            Stub.On(conn).GetProperty("SiteVersion").Will(Return.Value(new Version(2, 2, 0, 0)));
            var caps = _mocks.NewMock<IConnectionCapabilities>();
            Stub.On(conn).GetProperty("Capabilities").Will(Return.Value(caps));
            foreach (var rt in Enum.GetValues(typeof(ResourceTypes)))
            {
                Stub.On(caps).Method("GetMaxSupportedResourceVersion").With(rt).Will(Return.Value(new Version(1, 0, 0)));
            }

            var app = ObjectFactory.DeserializeEmbeddedFlexLayout(conn);
            var app2 = app.Clone();
            Assert.AreNotSame(app, app2);

            var fs = new OSGeo.MapGuide.ObjectModels.FeatureSource_1_0_0.FeatureSourceType();
            var fs2 = fs.Clone();
            Assert.AreNotSame(fs, fs2);

            var ld = ObjectFactory.CreateDefaultLayer(conn, LayerType.Vector, new Version(1, 0, 0));
            var ld2 = ld.Clone();
            Assert.AreNotSame(ld, ld2);

            var md = ObjectFactory.CreateMapDefinition(conn, "TestMap");
            var md2 = md.Clone();
            Assert.AreNotSame(md, md2);

            var wl = ObjectFactory.CreateWebLayout(conn, new Version(1, 0, 0), "Library://Test.MapDefinition");
            var wl2 = wl.Clone();
            Assert.AreNotSame(wl, wl2);

            var sl = new OSGeo.MapGuide.ObjectModels.SymbolLibrary_1_0_0.SymbolLibraryType();
            var sl2 = sl.Clone();
            Assert.AreNotSame(sl, sl2);

            var ssd = ObjectFactory.CreateSimpleSymbol(conn, new Version(1, 0, 0), "Test", "Test Symbol");
            var ssd2 = ssd.Clone();
            Assert.AreNotSame(ssd, ssd2);

            var csd = ObjectFactory.CreateCompoundSymbol(conn, new Version(1, 0, 0), "Test", "Test Symbol");
            var csd2 = csd.Clone();
            Assert.AreNotSame(csd, csd2);

            var pl = ObjectFactory.CreatePrintLayout(conn);
            var pl2 = pl.Clone();
            Assert.AreNotSame(pl, pl2);
        }
예제 #30
0
        public void TestGetImportantData_ExceptionHandeling()
        {
            //setup/arrange
            DateTime fromDate = DateTime.Now.Subtract(new TimeSpan(30, 0, 0, 0));
            DateTime toDate = DateTime.Now;
            Request request = new ImportantDataServiceRequestImpl();
            ImportantDataServiceRequest importantRequest = (ImportantDataServiceRequest)request;
            importantRequest.FromDate = fromDate;
            importantRequest.ToDate = toDate;
            DataSet response = new DataSet();
            Mockery mockery = new Mockery();
            Data mockData = mockery.NewMock<Data>();
            Expect.Once.On(mockData).Method("GetImportantDataWithDateRange").With(fromDate, toDate).Will(Throw.Exception(new Exception()));
            ImportantDataService service = new ImportantDataServiceImpl(mockData);

            //execute/act
            try
            {
                service.GetImportantData(request);
                //assert
                Assert.Fail("An Exception should have been thrown");
            }
            catch (ServiceException e)
            {
                Assert.AreEqual("The Service Invocation Failed", e.Message);
            }

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
예제 #31
0
        public void ShouldFailOnNullTypeResolveDependencyTest()
        {
            DependencyManager     dependencyManager;
            Mockery               mockery;
            IDependencyResolution mockDependencyResolution;
            Type   targetType;
            string selectorKey;
            object value;

            mockery = new Mockery();
            mockDependencyResolution = mockery.NewMock <IDependencyResolution>();

            dependencyManager = new DependencyManager();
            targetType        = null;
            selectorKey       = "x";

            value = dependencyManager.ResolveDependency(targetType, selectorKey);
        }
예제 #32
0
            protected override IAuthenticationService GetAuthenticationService()
            {
                IAuthenticationService svcAuth = m_mock.NewMock <IAuthenticationService>();

                var authResult = new AuthenticationResult()
                {
                    Authenticated = true
                };
                var authFailResult = new AuthenticationResult()
                {
                    Authenticated = false
                };

                Expect.Once.On(svcAuth).Method("AuthenticateByProof").WithAnyArguments().Will(Return.Value(authResult));
                //Expect.Once.On(svcAuth).Method("AuthenticateByProof").With("Dsn", "UnitTest").Will(Return.Value(authFailResult));

                return(svcAuth);
            }
예제 #33
0
        public void ShouldFailOnDisposedCreateInstanceWithCacheKeyTest()
        {
            Mockery          mockery;
            MockProxyFactory factory;

            MockProxyFactory.IInvokeDynamicFactory mockInvokeDynamicFactory;

            mockery = new Mockery();
            mockInvokeDynamicFactory = mockery.NewMock <MockProxyFactory.IInvokeDynamicFactory>();

            factory = new MockProxyFactory();

            Assert.IsNotNull(factory);

            factory.Dispose();

            factory.CreateInstance("test");
        }
예제 #34
0
        public void ShouldCreateInstanceWithInvokeDynamicTest()
        {
            Mockery            mockery;
            MockProxyFactory   factory;
            IMockObject        objectContract;
            IDynamicInvocation mockDynamicInvocation;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock <IDynamicInvocation>();

            factory = new MockProxyFactory();

            Assert.IsNotNull(factory);

            objectContract = factory.CreateInstance(mockDynamicInvocation);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
예제 #35
0
        public void ShouldRemoveResolution1Test()
        {
            DependencyManager     dependencyManager;
            Mockery               mockery;
            IDependencyResolution mockDependencyResolution;
            string selectorKey;

            mockery = new Mockery();
            mockDependencyResolution = mockery.NewMock <IDependencyResolution>();

            dependencyManager = new DependencyManager();
            selectorKey       = "x";

            dependencyManager.AddResolution <object>(selectorKey, mockDependencyResolution);
            dependencyManager.RemoveResolution <object>(selectorKey);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
예제 #36
0
        public void ShouldFailOnDisposedAddResolution1Test()
        {
            DependencyManager     dependencyManager;
            Mockery               mockery;
            IDependencyResolution mockDependencyResolution;
            string selectorKey;

            mockery = new Mockery();
            mockDependencyResolution = mockery.NewMock <IDependencyResolution>();

            Expect.Once.On(mockDependencyResolution).Method("Resolve").WithNoArguments().Will(Return.Value(null));

            dependencyManager = new DependencyManager();
            selectorKey       = "x";

            dependencyManager.Dispose();
            dependencyManager.AddResolution <object>(selectorKey, mockDependencyResolution);
        }
예제 #37
0
        public void ShouldFailOnDisposedRemoveResolutionTest()
        {
            DependencyManager     dependencyManager;
            Mockery               mockery;
            IDependencyResolution mockDependencyResolution;
            Type   targetType;
            string selectorKey;

            mockery = new Mockery();
            mockDependencyResolution = mockery.NewMock <IDependencyResolution>();

            dependencyManager = new DependencyManager();
            targetType        = typeof(object);
            selectorKey       = "x";

            dependencyManager.Dispose();
            dependencyManager.RemoveResolution(targetType, selectorKey);
        }
예제 #38
0
        public void Initialize()
        {
            mocks      = new Mockery();
            mockDevice = mocks.NewMock <IDDSUSBChip>();
            dds        = new AD9958(mockDevice);

            // Define some messages
            // FullDDSReset via EP1
            fullDDSReset = new Message(new byte[] { 0x03, 0x08, 0x0b });

            // Set to Two Level Modulation
            // Call to Function Register 1 according to Christian's implementation
            setTwoLevel = new Message(new byte[] { 0x01, 0xa8, 0x00, 0x20 });

            // Set to single tone
            // Call to channel function register with AFP select none,
            // the middle byte to default and the LSByte to all zeros
            // as in Christians code
            setSingleTone = new Message(new byte[] { 0x03, 0x00, 0x03, 0x00 });

            // Select both channels
            // Call to channel select register with both channels on and open and
            // write mode MSB serial 4 bit mode
            selectBothChannels = new Message(new byte[] { 0x00, (byte)(0xc0 + 0x36) });

            // Select channel zero
            selectChannelZero = new Message(new byte[] { 0x00, 0x76 });

            // Select channel one
            selectChannelOne = new Message(new byte[] { 0x00, 0xB6 });

            // Set frequency to 100 MHz
            // 0x33 0x33 0x33 0x33 / 2**32 = 0.2
            setFreqTo100MHz = new Message(new byte[] { 0x04, 0x33, 0x33, 0x33, 0x33 });

            // Set phase to zero
            setPhaseToZero = new Message(new byte[] { 0x05, 0x00, 0x00 });

            // Initialization after MasterReset
            initialization = new Message();
            initialization.Add(selectBothChannels);
            initialization.Add(setSingleTone);
            initialization.Add(setTwoLevel);
        }
예제 #39
0
        public void TestChangeUpdateOrder()
        {
            using (Mockery mockery = new Mockery()) {
                using (var manager = new InputManager()) {
                    IUpdateableSubscriber updateable = mockery.NewMock <IUpdateableSubscriber>();
                    manager.EnabledChanged     += updateable.EnabledChanged;
                    manager.UpdateOrderChanged += updateable.UpdateOrderChanged;

                    Expect.Once.On(updateable).Method("UpdateOrderChanged").WithAnyArguments();
                    manager.UpdateOrder = 123;
                    Assert.AreEqual(123, manager.UpdateOrder);

                    manager.UpdateOrderChanged -= updateable.UpdateOrderChanged;
                    manager.EnabledChanged     -= updateable.EnabledChanged;
                }

                mockery.VerifyAllExpectationsHaveBeenMet();
            }
        }
예제 #40
0
        private void InitPresentersAndViews()
        {
            using (PresenterFactory.BeginSharedPresenterTransaction(StructureMapContainerInit(), new BaseForm()))
            {
                var mocks = new Mockery();

                var chartView = DataHelper.GetView <IChartView>(mocks);

                m_ChartPresenter = DataHelper.GetPresenter <ChartPresenter>(chartView);
                Assert.IsNotNull(m_ChartPresenter);

                IPivotDetailView pivotView = PivotPresenterReportTests.GetPivotView(mocks);
                m_PivotDetailPresenter = DataHelper.GetPresenter <PivotDetailPresenter>(pivotView);
                Assert.IsNotNull(m_PivotDetailPresenter);

                var mapView = DataHelper.GetView <IMapView>(mocks);
                m_MapPresenter = DataHelper.GetPresenter <MapPresenter>(mapView);
                Assert.IsNotNull(m_MapPresenter);

                var layoutInfoView = DataHelper.GetView <IPivotInfoDetailView>(mocks);
                m_PivotInfoPresenter = DataHelper.GetPresenter <PivotInfoPresenter>(layoutInfoView);
                Assert.IsNotNull(m_PivotInfoPresenter);

                var viewDetailView = DataHelper.GetView <IViewDetailView>(mocks);
                m_ViewDetailPresenter = DataHelper.GetPresenter <ViewDetailPresenter>(viewDetailView);
                Assert.IsNotNull(m_ViewDetailPresenter);



                var layoutDetailView = DataHelper.GetView <ILayoutDetailView>(mocks);

                m_LayoutDetailPresenter = DataHelper.GetPresenter <LayoutDetailPresenter>(layoutDetailView);
                Assert.IsNotNull(m_LayoutDetailPresenter);

                var pivotGridView = mocks.NewMock <IAvrPivotGridView>();
                Expect.Once.On(pivotGridView).EventAdd("SendCommand", Is.Anything);
                m_PivotGridPresenter = PresenterFactory.SharedPresenter[pivotGridView] as AvrPivotGridPresenter;
                Assert.IsNotNull(m_PivotGridPresenter);


                mocks.VerifyAllExpectationsHaveBeenMet();
            }
        }
        public void ApplyToTest()
        {
            Mockery mockery = new Mockery();
            ICamera camera  = (ICamera)mockery.NewMock(typeof(ICamera));

            IsoSpeedEnum iso      = IsoSpeedEnum.iso50;
            ApertureEnum aperture = ApertureEnum.f10;
            ExposalEnum  exposal  = ExposalEnum.t1_100;

            Expect.Once.On(camera).Method("SetProperty").With(EDSDK.PropID_ISOSpeed, (int)iso);
            Expect.Once.On(camera).Method("SetProperty").With(EDSDK.PropID_Av, (int)aperture);
            Expect.Once.On(camera).Method("SetProperty").With(EDSDK.PropID_Tv, (int)exposal);

            ShootParameters parameters = new ShootParameters(iso, aperture, exposal);

            parameters.ApplyTo(camera);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
예제 #42
0
        public void ShouldFailOnNullTypeAddResolutionTest()
        {
            DependencyManager     dependencyManager;
            Mockery               mockery;
            IDependencyResolution mockDependencyResolution;
            Type   targetType;
            string selectorKey;

            mockery = new Mockery();
            mockDependencyResolution = mockery.NewMock <IDependencyResolution>();

            Expect.Once.On(mockDependencyResolution).Method("Resolve").WithNoArguments().Will(Return.Value(null));

            dependencyManager = new DependencyManager();
            targetType        = null;
            selectorKey       = "x";

            dependencyManager.AddResolution(targetType, selectorKey, mockDependencyResolution);
        }
예제 #43
0
        public void ShouldAddResolutionTest()
        {
            DependencyManager     dependencyManager;
            Mockery               mockery;
            IDependencyResolution mockDependencyResolution;
            Type   targetType;
            string selectorKey;

            mockery = new Mockery();
            mockDependencyResolution = mockery.NewMock <IDependencyResolution>();

            dependencyManager = new DependencyManager();
            targetType        = typeof(object);
            selectorKey       = "x";

            dependencyManager.AddResolution(targetType, selectorKey, mockDependencyResolution);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
        public void TestLineNumber()
        {
            Mockery           mockery = new Mockery();
            IProjectNode      pn      = mockery.NewMock <IProjectNode>();
            ProjectSerializer ps      = new ProjectSerializer("a\r\nb;\n\nc", null, null);

            Token t = ps.ReadTextToken(pn);

            Assert.AreEqual(1, t.LineNumber);

            Token newLine = ps.ReadLineBreakToken(pn);

            t = ps.ReadTextToken(pn);
            Assert.AreEqual(2, t.LineNumber);

            newLine = ps.ReadLineBreakToken(pn);

            t = ps.ReadTextToken(pn);
            Assert.AreEqual(4, t.LineNumber);
        }
예제 #45
0
        public void ShouldRunStorySuccessfully()
        {
            //Given
            Mockery mocks = new Mockery();
            SimplestPossibleWorld world = new SimplestPossibleWorld();
            IStory story = new FakeStory();

            //Story has scenarios
            IScenario scenario = mocks.NewMock <IScenario>();

            story.AddScenario(scenario);

            Expect.Once.On(scenario).Method("Run").Will(Return.Value(new Outcome(OutcomeResult.Passed, "yadda yadda")));

            //When
            story.Run();

            //Then
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
예제 #46
0
        public void SetUp()
        {
            mocks             = new Mockery();
            mocksGeolocations = mocks.NewMock <IGeolocations>();

            var geipoints = new List <GeoPointDto>();

            geipoints.Add(new GeoPointDto
            {
                DeviceSn  = "000010274",
                Imei      = "352848024123388",
                Latitude  = 0.1,
                Longitude = 0.2,
            });

            Expect.Once.On(mocksGeolocations)
            .Method("GetLocationsByImei")
            .With(Is.Anything, Is.Anything, Is.Anything)
            .Will(Return.Value(geipoints));
        }
        public void ShouldCreateInstanceWithInvokeDynamicAndDisposeInnerDisposableTest()
        {
            Mockery mockery;
            MockDynamicInvokerRealProxy mockDynamicInvokerRealProxy;
            IDynamicInvocation          mockDynamicInvocation;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock <IDynamicInvocation>();

            Expect.Once.On(mockDynamicInvocation).Method("Dispose").WithNoArguments();

            mockDynamicInvokerRealProxy = new MockDynamicInvokerRealProxy(mockDynamicInvocation);
            Assert.IsFalse(mockDynamicInvokerRealProxy.Disposed);
            Assert.IsNotNull(mockDynamicInvokerRealProxy);

            mockDynamicInvokerRealProxy.Dispose();
            Assert.IsTrue(mockDynamicInvokerRealProxy.Disposed);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
        public void ShouldNotFailOnDoubleDisposeTest()
        {
            Mockery mockery;
            MockDynamicInvokerRealProxy mockDynamicInvokerRealProxy;
            IDynamicInvocation          mockDynamicInvocation;

            mockery = new Mockery();
            mockDynamicInvocation = mockery.NewMock <IDynamicInvocation>();

            Expect.Once.On(mockDynamicInvocation).Method("Dispose").WithNoArguments();

            mockDynamicInvokerRealProxy = new MockDynamicInvokerRealProxy(mockDynamicInvocation);

            Assert.IsNotNull(mockDynamicInvokerRealProxy);

            mockDynamicInvokerRealProxy.Dispose();
            mockDynamicInvokerRealProxy.Dispose();

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
예제 #49
0
        public void Initialize()
        {
            mocks      = new Mockery();
            mockDevice = mocks.NewMock <IDDSUSBChip>();
            dds        = new AD9958(mockDevice);

            // Define some common calls

            // Set to Two Level Modulation
            // Call to Function Register 1 according to Christian's implementation
            setTwoLevel = new Message(new byte[] { 0x01, 0xa8, 0x00, 0x20 });

            // Set to single tone
            // Call to channel function register with AFP select none,
            // the middle byte to default and the LSByte to all zeros
            // as in Christians code
            setSingleTone = new Message(new byte[] { 0x03, 0x00, 0x03, 0x00 });

            // Select both channels
            // Call to channel select register with both channels on and open and
            // write mode MSB serial 4 bit mode
            selectBothChannels = new Message(new byte[] { 0x00, (byte)(0xc0 + 0x36) });

            // Full_DDS_Reset via EP1
            fullDDSReset = new Message(new byte[] { 0x03, 0x08, 0x0b });

            // Start_Transfer via EP1
            startTransfer = new Message(0x03, 0x03, 0x06);

            // Stop Transfer via EP1
            stopTransfer = new Message(0x03, 0x04, 0x07);

            // ListplayMode via EP1 (10 byte length)
            listPlayMode10bytes = new Message(0x04, 0x0b, 0x0a, 0x19);

            // StartListplayMode via EP1
            startListPlayMode = new Message(0x03, 0x0c, 0x0f);

            // StopListplay mode via EP1
            stopListPlayMode = new Message(0x03, 0x0e, 0x11);
        }
예제 #50
0
        public void Initialize()
        {
            mocks = new Mockery();
            mockMicrocontroller = mocks.NewMock <IDDSUSBChip>();
            dds = new AD9958(mockMicrocontroller);

            // Define some messages
            // Select channel zero
            selectChannelZero = new Message(new byte[] { 0x00, 0x76 });

            // Set to Two Level Modulation
            // Call to Function Register 1 according to Christian's implementation
            setTwoLevel = new Message(new byte[] { 0x01, 0xa8, 0x00, 0x20 });

            // Set to frequency modulation
            // Call to channel function register with AFP select FM,
            // the middle byte to default and the LSByte to all zeros
            // as in Christians code
            selectFrequencyModulation = new Message(new byte[] { 0x03, 0x80, 0x03, 0x00 });

            // Set frequency tuning word of current channel to 1 MHz
            // 0x00 0x83 0x12 0x6E / 2**32 = 0.002
            setFreqTuningWord1MHz = new Message(new byte[] { 0x04, 0x00, 0x83, 0x12, 0x6F });

            // Set Channel Word Register 1 to 2 MHz
            setChanWordOne2MHz = new Message(new byte[] { 0x0A, 0x01, 0x06, 0x24, 0xDD });

            // Set to phase modulation
            // Call to channel function register with AFP select PM,
            // the middle byte to default and the LSByte to all zeros
            // as in Christians code
            selectPhaseModulation = new Message(new byte[] { 0x03, 0xC0, 0x03, 0x00 });

            // Set phase tuning word to zero
            setPhaseTuningWordZero = new Message(new byte[] { 0x05, 0x00, 0x00 });

            // Set channel register word 1 to pi (resolution 14bit)
            // Pi is 2**13 (10 0000 0000) we have to MSB align it in the 32 bit CW1 register
            // where we set all others to zero
            setChanWordOnePi = new Message(new byte[] { 0x0A, 0x80, 0x00, 0x00, 0x00 });
        }
        public void ShouldSetupGivens()
        {
            //Given
            Mockery mocks = new Mockery();

            SimplestPossibleWorld world = new SimplestPossibleWorld();

            IGiven aGiven = mocks.NewMock <IGiven>();

            Expect.Once.On(aGiven).Method("Setup").With(world);

            List <IGiven> l = new List <IGiven>();

            l.Add(aGiven);
            Scenario.Scenario scenario = new MyScenario(l, null, null, world);
            //When
            scenario.SetupGivens();

            //Then
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
예제 #52
0
        public void ShouldFailOnNotAssignableResolveDependencyTest()
        {
            DependencyManager     dependencyManager;
            Mockery               mockery;
            IDependencyResolution mockDependencyResolution;
            Type   targetType;
            string selectorKey;
            object value;

            mockery = new Mockery();
            mockDependencyResolution = mockery.NewMock <IDependencyResolution>();

            Expect.Once.On(mockDependencyResolution).Method("Resolve").WithNoArguments().Will(Return.Value(1));

            dependencyManager = new DependencyManager();
            targetType        = typeof(IDisposable);
            selectorKey       = "yyy";

            dependencyManager.AddResolution(targetType, selectorKey, mockDependencyResolution);
            value = dependencyManager.ResolveDependency <IDisposable>(selectorKey);
        }
예제 #53
0
        //[Explicit("Causes Debug.Assert")]
        public void InitZeroHandle()
        {
            const uint BadZeroStackId = 0;
            var        mocks          = new Mockery();
            var        api            = mocks.NewMock <IBluetopiaApi>();

            Expect.Exactly(2).On(api).Method("BSC_Initialize")
            .WithAnyArguments()      // TO-DO
            .Will(Return.Value((int)BadZeroStackId));
            //----
            try {
                BluetopiaTesting.HackAllowShutdownCall(api);
                BluetopiaFactory fcty = new BluetopiaFactory(api);
                Assert.Fail("should have thrown!");
            } catch (BluetopiaSocketException ex) {
                Assert.AreEqual((int)BluetopiaError.OK, ex.BluetopiaErrorCode, "BluetopiaErrorCode");
                Assert.AreEqual(BluetopiaError.OK.ToString(), ex.BluetopiaError, "BluetopiaError");
            }
            //
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
예제 #54
0
        public void FindElementOneByEmpty()
        {
            Mockery    mock   = new Mockery();
            IAllDriver driver = mock.NewMock <IAllDriver>();
            var        elems  = new List <IWebElement>().AsReadOnly();

            Expect.Once.On(driver).Method("FindElementsByName").With("cheese").Will(Return.Value(elems));

            ByChained by = new ByChained(By.Name("cheese"));

            try
            {
                by.FindElement(driver);
                Assert.Fail("Expected NoSuchElementException!");
            }
            catch (NoSuchElementException)
            {
                mock.VerifyAllExpectationsHaveBeenMet();
                Assert.Pass();
            }
        }
예제 #55
0
        public void verifica_que_va_a_la_base_de_docentes_una_sola_vez()
        {
            string source = @"      |Id     |Documento   |Apellido     |Nombre     |Telefono      |Mail     |Direccion  |IdModalidad  |ModalidadDescripcion |IdArea |NombreArea                         |IdBaja
                                    |01     |31507315    |Cevey        |Belén      |A111          |belen@ar |Calle      |1            |fines                |0      |Ministerio de Desarrollo Social    |0
                                    |02     |31041236    |Caino        |Fernando   |A222          |fer@ar   |Av         |1            |fines                |1      |Unidad Ministrio                   |0
                                    |05     |31507315    |Cevey        |Belén      |A111          |belen@ar |Calle      |1            |fines                |1      |Unidad Ministrio                   |0
                                    |03     |31507315    |Cevey        |Belén      |A111          |belen@ar |Calle      |1            |fines                |621    |Secretaría de Deportes             |0";

            var mocks         = new Mockery();
            var conexion      = mocks.NewMock <IConexionBD>();
            var repo_docentes = new RepositorioDeDocentes(conexion, TestObjects.RepoCursosMockeado());
            var resultado     = TablaDeDatos.From(source);

            Expect.Once.On(conexion).Method("Ejecutar").WithAnyArguments().Will(Return.Value(resultado));

            repo_docentes.GetDocentes();
            var docentes = repo_docentes.GetDocentes();

            mocks.VerifyAllExpectationsHaveBeenMet();
            Assert.AreEqual(4, docentes.Count);
        }
        public void TestLoadCommandBlockPythonStyle()
        {
            Mockery            mockery        = new Mockery();
            IProjectSerializer mockSerializer = mockery.NewMock <IProjectSerializer>();

            using (mockery.Ordered)
            {
                Expect.Once.On(mockSerializer).GetProperty("Position").Will(Return.Value(0));
                Expect.Once.On(mockSerializer).Method("ReadLineBreakToken").Will(Return.Value(new Token(TokenType.LineBreak, "\r\n", 0, 2)));
                Expect.Once.On(mockSerializer).Method("ReadIndentationToken").Will(Return.Value(new Token(TokenType.LineBreak, "\t\t", 2, 2)));
                Expect.Once.On(mockSerializer).Method("GetIndentationLevel").Will(Return.Value(2));
                Expect.Once.On(mockSerializer).Method("ReadBlockStarterToken").Will(Return.Value(null));
                Expect.Once.On(mockSerializer).GetProperty("LastIndentationLevel").Will(Return.Value(0));
                Expect.Once.On(mockSerializer).GetProperty("Done").Will(Return.Value(false));
                Expect.Once.On(mockSerializer).Method("GetIndentationLevel").Will(Return.Value(2));
                Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(new Token(TokenType.Text, "token", 4, 5)));
                Expect.Once.On(mockSerializer).GetProperty("LineNumber").Will(Return.Value(3));
                Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(new Token(TokenType.Text, "consonants", 9, 10)));
                Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(null));
                Expect.Once.On(mockSerializer).Method("ReadLineBreakToken").Will(Return.Value(new Token(TokenType.LineBreak, "\r\n", 19, 2)));
                Expect.Once.On(mockSerializer).GetProperty("Done").Will(Return.Value(false));
                Expect.Once.On(mockSerializer).Method("ReadIndentationToken").Will(Return.Value(new Token(TokenType.Indentation, "\t\t", 21, 2)));
                Expect.Once.On(mockSerializer).Method("GetIndentationLevel").Will(Return.Value(2));
                Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(new Token(TokenType.Command, "rule", 23, 4)));
                Expect.Once.On(mockSerializer).GetProperty("LineNumber").Will(Return.Value(3));
                Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(new Token(TokenType.Text, "second", 27, 6)));
                Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(null));
                Expect.Once.On(mockSerializer).Method("ReadLineBreakToken").Will(Return.Value(new Token(TokenType.LineBreak, "\r\n", 19, 2)));
                Expect.Once.On(mockSerializer).GetProperty("Done").Will(Return.Value(false));
                Expect.Once.On(mockSerializer).Method("ReadIndentationToken").Will(Return.Value(new Token(TokenType.Indentation, "\t", 33, 1)));
                Expect.Once.On(mockSerializer).Method("GetIndentationLevel").Will(Return.Value(1));
                Expect.Once.On(mockSerializer).Method("RollBackToken");
            }

            CommandBlockNode cbn = new CommandBlockNode(mockSerializer);

            Assert.AreEqual(2, cbn.Commands.Count);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
예제 #57
0
        public void verificacion_cache_vacia_para_alumnos()
        {
            string source = @"      |Id     |Documento   |Apellido     |Nombre     |Telefono      |Mail     |Direccion  |IdModalidad  |ModalidadDescripcion |IdArea |NombreArea                         |IdBaja
                                    |01     |31507315    |Cevey        |Belén      |A111          |belen@ar |Calle      |1            |fines                |0      |Ministerio de Desarrollo Social    |0";

            var mocks       = new Mockery();
            var conexion    = mocks.NewMock <IConexionBD>();
            var repo_alumno = new RepositorioDeAlumnos(conexion, TestObjects.RepoCursosMockeado(), TestObjects.RepoModalidadesMockeado());
            var resultado   = TablaDeDatos.From(source);

            resultado.Clear();

            Expect.Once.On(conexion).Method("Ejecutar").WithAnyArguments().Will(Return.Value(resultado));

            repo_alumno.GetAlumnos();
            var alumnos = repo_alumno.GetAlumnos();

            alumnos = repo_alumno.GetAlumnos();

            mocks.VerifyAllExpectationsHaveBeenMet();
            Assert.AreEqual(0, alumnos.Count);
        }
예제 #58
0
        public void RefreshedCacheOnUserCallAfterDaysTest()
        {
            var configuration = new SchedulerConfigurationSection
            {
                TimeOfSchedulerRuns               = new TimeSpan(0, 0, 0, 0),
                ImmediatelyRunScheduler           = false,
                RefreshedCacheOnUserCallAfterDays = 1,
                SecondsBetweenSchedulerTasks      = 0,
            };

            var mocks          = new Mockery();
            var configStrategy = mocks.NewMock <ISchedulerConfigurationStrategy>();

            Expect.Once.On(configStrategy).Method("GetConfigurationSection").Will(Return.Value(configuration));
            Expect.Once.On(configStrategy).Method("GetServiceDisplayName").Will(Return.Value("service name"));

            Container c = new Container();

            c.Configure(r => { r.For <ISchedulerConfigurationStrategy>().Use(configStrategy); });
            Assert.AreEqual(1, (c.GetInstance <AVRFacade>()).RefreshedCacheOnUserCallAfterDays);

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
예제 #59
0
        public void ShouldNotFailOnDoubleDisposedAddResolution1Test()
        {
            DependencyManager     dependencyManager;
            Mockery               mockery;
            IDependencyResolution mockDependencyResolution;

            mockery = new Mockery();
            mockDependencyResolution = mockery.NewMock <IDependencyResolution>();

            dependencyManager = new DependencyManager();

            Assert.IsFalse(dependencyManager.Disposed);

            dependencyManager.Dispose();

            Assert.IsTrue(dependencyManager.Disposed);

            dependencyManager.Dispose();

            Assert.IsTrue(dependencyManager.Disposed);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
        public void SetUp()
        {
            mockery                          = new Mockery();
            mockStreamReader                 = mockery.NewMock <IStreamReader>();
            allWordsTrieRoot                 = new Dictionary <Char, TrieNode <Char> >();
            allWords                         = new HashSet <String>();
            fromCharacterFrequencies         = new FrequencyTable <Char>();
            characterSubstitutionFrequencies = new FrequencyTable <CharacterSubstitution>();
            List <String> testWords = new List <String>()
            {
                "read",
                "bead",
                "fail",
                "dead",
                "road",
                "reed",
                "calm",
                "real",
                "rear"
            };
            Func <String, Boolean> wordFilterFunction   = new Func <String, Boolean>((inputString) => { return(true); });
            CharacterTrieBuilder   characterTrieBuilder = new CharacterTrieBuilder();

            using (mockery.Ordered)
            {
                foreach (String currentTestWord in testWords)
                {
                    Expect.Once.On(mockStreamReader).GetProperty("EndOfStream").Will(Return.Value(false));
                    Expect.Once.On(mockStreamReader).Method("ReadLine").WithNoArguments().Will(Return.Value(currentTestWord));
                }
                Expect.Once.On(mockStreamReader).GetProperty("EndOfStream").Will(Return.Value(true));
                Expect.Once.On(mockStreamReader).Method("Dispose").WithNoArguments();
            }
            dataStructureUtilities.PopulateAdjacentWordDataStructures(mockStreamReader, characterTrieBuilder, wordFilterFunction, allWordsTrieRoot, allWords, fromCharacterFrequencies, characterSubstitutionFrequencies);
            mockery.ClearExpectation(mockStreamReader);
            testCandidateWordPriorityCalculator = new CandidateWordPriorityCalculator(20, 1, 1, 1, 1, allWordsTrieRoot, fromCharacterFrequencies, characterSubstitutionFrequencies);
        }