Example #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            GWydiRWizardUI ui = new GWydiRWizardUI();
            Wizard wizard = new Wizard(); // need to add an object to congiure the wizard from subscritions/config files
            AuthorisationModel authModel = new AuthorisationModel(ui, wizard);
            ConfigurationModel confModel = new ConfigurationModel(ui, wizard);
            ProductionModel prodModel = new ProductionModel(ui, wizard);

            Application.Run(ui);
        }
        public void ChangedCerSelectedHandlerHasSubscriptionTest()
        {
            //Arange
            IWizard mockWizard = MockRepository.GenerateMock<IWizard>();
            mockWizard.Expect(x => x.GetCertList()).Return(new List<string>() { string.Empty });
            mockWizard.Expect(x => x.HasSubscription(Arg<string>.Is.Anything, Arg<string>.Is.Anything)).Return(true);

            IAuthorisationView mockView = MockRepository.GenerateMock<IAuthorisationView>();
            mockView.Expect(x => x.DisableCreate());
            mockView.Expect(x => x.EnableNext());

            model = new OverRiddenAuthorisationModel_1(mockView, mockWizard);

            //Act
            model.ChangedCertificateSelectionHandler(0);

            //Assert
            mockView.VerifyAllExpectations();
            mockWizard.VerifyAllExpectations();
        }
        public void ChangedSIDSelectionHandlerHasNoCertificatesTest()
        {
            //Arrange
            IWizard mockWizard = MockRepository.GenerateMock<IWizard>();
            mockWizard.Expect(x => x.GetSIDList()).Return(new List<string>() { string.Empty });
            mockWizard.Expect(x => x.GetSubscriptions()).Return(new List<Subscription>());

            IAuthorisationView mockView = MockRepository.GenerateStub<IAuthorisationView>();

            model = new OverRiddenAuthorisationModel_1(mockView, mockWizard);

            //Act
            int index = model.ChangedSIDSelectionHandler(0);

            //Assert
            mockWizard.VerifyAllExpectations();
            Assert.IsTrue(index == -1);
        }
 public void Setup()
 {
     model = new AuthorisationModel();
 }
        public void NextHandlerValidSubscriptionNoLocalCertificateTest()
        {
            //Arrange
            IAuthorisationView mockView = MockRepository.GenerateMock<IAuthorisationView>();
            mockView.Expect(x => x.GetSelectedSubscription()).Return(string.Empty);
            mockView.Expect(x => x.GetSelectedCertificate()).Return(string.Empty);

            IViewError mockErrorView = MockRepository.GenerateStrictMock<IViewError>();
            mockErrorView.Expect(x => x.NotifyOfError(Arg<Exception>.Is.Anything));

            IWizard mockWizard = MockRepository.GenerateMock<IWizard>();
            mockWizard.Expect(x => x.HasSubscription(Arg<string>.Is.Anything, Arg<string>.Is.Anything)).Return(true);
            mockWizard.Expect(x => x.GetSTSThumbPrint(Arg<string>.Is.Anything, Arg<string>.Is.Anything)).Return(String.Empty);

            CertificateManager mockManager = MockRepository.GenerateMock<CertificateManager>();
            mockManager.Expect(x => x.CertificateExistsLocally(Arg<string>.Is.Anything)).Return(false);

            X509Certificate2 mockCertificate = MockRepository.GenerateStub<X509Certificate2>();
            mockCertificate.Stub(x => x.Thumbprint).Return(string.Empty);

            model = new OverRiddenAuthorisationModel_1(mockView,mockWizard,mockManager,mockErrorView);

            model.certificateSTS = mockCertificate;

            //Act
            model.NextHandler(new object(), new EventArgs());

            //Assert
            mockView.VerifyAllExpectations();
            mockWizard.VerifyAllExpectations();
            mockErrorView.VerifyAllExpectations();
            mockManager.VerifyAllExpectations();
        }
        public void NextHandlerInvalidSubscriptionTest()
        {
            //Arrange
            IAuthorisationView mockView = MockRepository.GenerateMock<IAuthorisationView>();
            mockView.Expect(x => x.GetSelectedSubscription()).Return(string.Empty);
            mockView.Expect(x => x.GetSelectedCertificate()).Return(string.Empty);

            IWizard mockWizard = MockRepository.GenerateMock<IWizard>();
            mockWizard.Stub(x => x.AddSubscription(Arg<string>.Is.Anything, Arg<string>.Is.Anything,
                Arg<string>.Is.Anything, Arg<string>.Is.Anything));
            mockWizard.Expect(x => x.HasSubscription(Arg<string>.Is.Anything, Arg<string>.Is.Anything)).Return(false);
            mockWizard.Stub(x => x.SaveSubscriptions());

            X509Certificate2 mockCertificate = MockRepository.GenerateStub<X509Certificate2>();
            mockCertificate.Stub(x => x.Thumbprint).Return(string.Empty);

            model = new OverRiddenAuthorisationModel_1(mockView,mockWizard);
            model.certificateSTS = mockCertificate;

            //Act
            model.NextHandler(new object(), new EventArgs());

            //Assert
            mockView.VerifyAllExpectations();
            mockWizard.VerifyAllExpectations();
        }
        public void NewSubscriptionHandlerWithException()
        {
            //Arrange
            IAuthorisationView mockView = MockRepository.GenerateMock<IAuthorisationView>();
            mockView.Stub(x => x.DisplaySubsriptions(Arg<List<string>>.Is.Anything));

            IWizard mockWizard = MockRepository.GenerateMock<IWizard>();
            mockWizard.Expect(x => x.addSID(Arg<string>.Is.Anything)).Throw(new InvalidSIDException());
            mockWizard.Expect(x => x.GetSIDList()).Return(new List<string>());

            IViewError mockErrorView = MockRepository.GenerateMock<IViewError>();
            mockErrorView.Expect(x => x.NotifyOfError(Arg<Exception>.Is.Anything));

            model = new OverRiddenAuthorisationModel_1(mockView, mockWizard, mockErrorView);

            //Act
            model.NewSubscriptionHandler(string.Empty);

            //Assert
            mockView.VerifyAllExpectations();
            mockWizard.VerifyAllExpectations();
            mockErrorView.VerifyAllExpectations();
        }
        public void NewSubscriptionHandlerNoExceptionTest()
        {
            //Arrange
            IAuthorisationView mockView = MockRepository.GenerateMock<IAuthorisationView>();
            mockView.Expect(x => x.DisplaySubsriptions(Arg<List<string>>.Is.Anything));

            IWizard mockWizard = MockRepository.GenerateMock<IWizard>();
            mockWizard.Expect(x => x.addSID(Arg<string>.Is.Anything));

            model = new OverRiddenAuthorisationModel_1(mockView, mockWizard);

            //Act
            model.NewSubscriptionHandler(string.Empty);

            //Assert
            mockView.VerifyAllExpectations();
            mockWizard.VerifyAllExpectations();
        }
        public void NewCertificateHandlerTest()
        {
            //Arrange
            IWizard mockWizard = MockRepository.GenerateMock<IWizard>();
            mockWizard.Expect(x => x.AddCertificate(Arg<string>.Is.Anything));

            IAuthorisationView mockView = MockRepository.GenerateMock<IAuthorisationView>();
            mockView.Expect(x => x.DisplayCertificates(Arg<List<string>>.Is.Anything));

            model = new OverRiddenAuthorisationModel_1(mockView, mockWizard);

            //Act
            model.NewCertificateHandler(new string[] {string.Empty,string.Empty});

            //Asssert
            mockWizard.VerifyAllExpectations();
            mockView.VerifyAllExpectations();
        }
        public void CreateButtonHandlerTest()
        {
            //Arrange
            IWizard mockWizard = MockRepository.GenerateStub<IWizard>();

            FileWriter mockWriter = MockRepository.GenerateMock<FileWriter>();
            mockWriter.Expect(x => x.Write(Arg<string>.Is.Anything, Arg<byte[]>.Is.Anything));

            IAuthorisationView mockView = MockRepository.GenerateMock<IAuthorisationView>();
            mockView.Expect(x => x.DisableCreate());
            mockView.Expect(x => x.EnableNext());

            CertificateMaker mockMaker = MockRepository.GenerateMock<CertificateMaker>();
            System.IO.MemoryStream mockSteam = MockRepository.GenerateStub<System.IO.MemoryStream>();
            mockSteam.Stub(x => x.ToArray()).Return(new byte[1]);
            PkcsCertificate mockCert = MockRepository.GenerateMock<PkcsCertificate>();
            X509Certificate2 mockCert2 = MockRepository.GenerateStub<X509Certificate2>();
            mockCert2.Stub(x => x.GetRawCertData()).Return(new byte[1]);
            mockCert.Stub(x => x.GetX509Certificate2(Arg<X509KeyStorageFlags>.Is.Anything)).Return(mockCert2);
            mockCert.Stub(x => x.GetCertificateStream()).Return(new System.IO.MemoryStream());
            mockMaker.Expect(x => x.MakeCertificate(Arg<string>.Is.Anything, Arg<string>.Is.Anything)).Return(mockCert);

            X509Store mockStore = MockRepository.GenerateStub<X509Store>(Arg<StoreName>.Is.Anything, Arg<StoreLocation>.Is.Anything);
            mockStore.Expect(x => x.Open(Arg<OpenFlags>.Is.Anything));
            mockStore.Expect(x => x.Add(mockCert2));
            mockStore.Expect(x => x.Close());

            model = new OverRiddenAuthorisationModel_1(mockView, mockWizard, mockMaker, mockWriter, mockStore);

            //Act
            model.CreateButtonHandler(new object(), new EventArgs());

            //Assert
            mockView.VerifyAllExpectations();
            mockMaker.VerifyAllExpectations();
            mockWriter.VerifyAllExpectations();
            mockStore.VerifyAllExpectations();
        }
Example #11
0
 public ViewModel()
 {
     Authorisation = new AuthorisationModel();
 }