示例#1
0
        public void CreateTest()
        {
            PartialViewResult rv = (PartialViewResult)_controller.Create();

            Assert.IsInstanceOfType(rv.Model, typeof(ConnectionVM));

            ConnectionVM vm = rv.Model as ConnectionVM;
            Connection   v  = new Connection();

            v.Name     = "KgH";
            v.Host     = "gMTL";
            v.Port     = 12;
            v.Database = "tBEa";
            v.Username = "******";
            v.Password = "******";
            v.ID       = 10;
            vm.Entity  = v;
            _controller.Create(vm);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <Connection>().FirstOrDefault();

                Assert.AreEqual(data.Name, "KgH");
                Assert.AreEqual(data.Host, "gMTL");
                Assert.AreEqual(data.Port, 12);
                Assert.AreEqual(data.Database, "tBEa");
                Assert.AreEqual(data.Username, "2jZ");
                Assert.AreEqual(data.Password, "1O0xDQf");
                Assert.AreEqual(data.ID, 10);
                Assert.AreEqual(data.CreateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10);
            }
        }
        public void Create_Post_Should_Redisplay_With_Errors_When_Duplicate_Name()
        {
            // arrange
            FakeConnectionRepository connectionRepository = new FakeConnectionRepository();

            connectionRepository.AddConnection(new ConnectionModel()
            {
                ConnectionId = 1, Name = "connection1"
            });

            FormCollection formCollection = new FormCollection();

            formCollection["Name"] = "connection1";
            formCollection["ConnectionParameterKey1"]   = "key1";
            formCollection["ConnectionParameterValue1"] = "value1";

            ConnectionController connectionController = new ConnectionController(connectionRepository);

            connectionController.ValueProvider = formCollection.ToValueProvider();

            // act
            ViewResult viewResult = connectionController.Create(formCollection) as ViewResult;

            // assert
            Assert.IsTrue(viewResult.ViewData.ModelState["Name"].Errors.Count == 1);
        }
        public void CreateConnection()
        {
            Connection connection = controller.Create(model);

            Assert.True(connectionRepository.Exists(connection));

            Assert.AreEqual(model.OS, connection.OS);
            Assert.AreEqual(model.Navigator, connection.Navigator);
            Assert.AreEqual(model.RemoteAddress, connection.RemoteAddress);
            Assert.AreEqual(model.Persisted, connection.IsPersistent);


            Assert.AreEqual(account, connection.Account);

            Assert.NotNull(connection.BeginDate);
            Assert.Null(connection.EndDate);
            Assert.False(connection.IsClosed);
        }
        public void Create_Get_Should_Return_View()
        {
            // arrange
            ConnectionController connectionController = new ConnectionController(new FakeConnectionRepository());

            // act
            ViewResult viewResult = connectionController.Create() as ViewResult;

            // assert
            Assert.IsNotNull(viewResult);
        }
        public void Create_Post_Should_Not_Create_Connection_When_Invalid()
        {
            // arrange
            FakeConnectionRepository connectionRepository = new FakeConnectionRepository();
            ConnectionController     connectionController = new ConnectionController(connectionRepository);

            FormCollection formCollection = new FormCollection();

            connectionController.ValueProvider = formCollection.ToValueProvider();

            // act
            ViewResult viewResult = connectionController.Create(formCollection) as ViewResult;

            // assert
            Assert.IsTrue(connectionRepository.Count == 0);
        }
        public void Create_Post_Should_Redisplay_With_Errors_When_Invalid()
        {
            // arrange
            FakeConnectionRepository connectionRepository = new FakeConnectionRepository();
            ConnectionController     connectionController = new ConnectionController(connectionRepository);

            FormCollection formCollection = new FormCollection();

            connectionController.ValueProvider = formCollection.ToValueProvider();

            // act
            ViewResult viewResult = connectionController.Create(formCollection) as ViewResult;

            // assert
            Assert.IsTrue(viewResult.ViewData.Model is ConnectionModel);
            Assert.IsTrue(viewResult.ViewData.ModelState["Name"].Errors.Count > 0);
        }
示例#7
0
        public void BeforeEach()
        {
            IServiceCollection serviceCollection = ServiceConfiguration.InitServiceCollection();
            IServiceProvider   serviceProvider   = ServiceConfiguration.BuildServiceProvider();

            Configuration = serviceProvider.GetRequiredService <IConfiguration>();

            controller           = serviceProvider.GetRequiredService <AuthorizationController>();
            connectionController = serviceProvider.GetRequiredService <ConnectionController>();
            accountController    = serviceProvider.GetRequiredService <AccountController>();

            connectionRepository    = serviceProvider.GetRequiredService <IRepository <Connection, long> >();
            authorizationRepository = serviceProvider.GetRequiredService <IRepository <Authorization, long> >();
            clientRepository        = serviceProvider.GetRequiredService <IRepository <Client, string> >();

            account = accountController.Create(new AddAccountModel
            {
                Name     = "Chendjou",
                Surname  = "Caleb",
                Email    = "*****@*****.**",
                Password = "******",
            });

            connection = connectionController.Create(new LoginModel
            {
                Email    = account.Email,
                Password = "******"
            });

            client = clientRepository.Save(new Client
            {
                Name       = "Identity Client",
                SecretCode = Guid.NewGuid().ToString()
            });


            model = new AuthorizeModel
            {
                ClientId     = client.Id,
                SecretCode   = client.SecretCode,
                ConnectionId = connection.Id
            };
        }
        public void Create_Post_Should_Create_Connection_When_Valid()
        {
            // arrange
            FakeConnectionRepository connectionRepository = new FakeConnectionRepository();
            ConnectionController     connectionController = new ConnectionController(connectionRepository);

            FormCollection formCollection = new FormCollection();

            formCollection["Name"] = "connection1";
            formCollection["ConnectionParameterKey1"]   = "key1";
            formCollection["ConnectionParameterValue1"] = "value1";

            connectionController.ValueProvider = formCollection.ToValueProvider();

            // act
            ViewResult viewResult = connectionController.Create(formCollection) as ViewResult;

            // assert
            Assert.IsTrue(connectionRepository.Count == 1);
        }