コード例 #1
0
        public void Process_ExistingPage()
        {
            // Arrange
            var dataStorePage = Models.CreateFirstTimeHelp(id: 84926);

            var dataStoreBullets = new List<Bullet>();
            dataStoreBullets.Add(Models.CreateBullet(id: 54829, pageId: dataStorePage.Id));
            dataStoreBullets.Add(Models.CreateBullet(id: 29334, pageId: dataStorePage.Id));
            var updatedBullet = dataStoreBullets[0];
            var deletedBullet = dataStoreBullets[1];

            var clientHelp = new FirstTimeHelp
            {
                Id = dataStorePage.Id,			// Same id as data store page because this is an existing page.
                Title = dataStorePage.Title,
                Content = dataStorePage.Content,
            };
            clientHelp.Bullets.Add(Models.CreateBullet(clientHelp.Id));
            clientHelp.Bullets.Add(dataStoreBullets[0]);
            var newBullet = clientHelp.Bullets[0];

            var helpRepository = Mocks.Create<IFirstTimeHelpRepository>();
            helpRepository.Setup(r => r.Update(It.Is<FirstTimeHelp>(p => p.Id == clientHelp.Id)));

            var bulletRepository = Mocks.Create<IBulletRepository>();
            bulletRepository.Setup(r => r.ReadByPageId(clientHelp.Id)).Returns(dataStoreBullets);
            bulletRepository.Setup(r => r.Create(It.Is<Bullet>(b => b.Text == newBullet.Text)));
            bulletRepository.Setup(r => r.Update(It.Is<Bullet>(b => b.Id == updatedBullet.Id)));
            bulletRepository.Setup(r => r.Delete(deletedBullet.Id));

            var serializer = new JavaScriptSerializer();
            var requestData = serializer.Serialize(clientHelp);
            var processor = new SaveFirstTimeHelpRequestProcessor(bulletRepository.Object, helpRepository.Object);

            // Act
            var result = processor.Process(requestData);

            // Assert
            Assert.That(result, Is.Not.Null, "A response state instance should be returned.");
            Assert.That(result.ContentType, Is.EqualTo(ContentTypes.Json), "The response content should contain JSON.");
            var resultHelp = serializer.Deserialize<FirstTimeHelp>(result.Content);
            Assert.That(resultHelp.Id, Is.EqualTo(clientHelp.Id), "The page id should not change.");
            Assert.That(resultHelp.Bullets.Count, Is.EqualTo(clientHelp.Bullets.Count), "The returned page should have the same number of bullets as the client page.");
            foreach (var clientBullet in clientHelp.Bullets)
            {
                Assert.That(resultHelp.Bullets.Where(resultBullet => resultBullet.Text == clientBullet.Text).Count(), Is.EqualTo(1), "All bullets in client model should be returned in the result.");
            }
            Mocks.VerifyAll();
        }
コード例 #2
0
        public void Create(FirstTimeHelp help)
        {
            using (var connection = SqlConnectionFactory.GetConnection())
            using (var command = connection.CreateCommand())
            {
                command.CommandType = CommandType.Text;
                command.CommandText = SqlScripts.FirstTimeHelp_Create;
                AddParameters(help, command);

                connection.Open();
                help.Id = (int)command.ExecuteScalar();
            }

            MatchUrls_CreateByHelpId(help.Id, help.MatchUrls);
        }
コード例 #3
0
        public void Import(FirstTimeHelp help)
        {
            using (var connection = SqlConnectionFactory.GetConnection())
            using (var command = connection.CreateCommand())
            {
                command.CommandType = CommandType.Text;
                command.CommandText = SqlScripts.FirstTimeHelp_Import;
                AddParameters(help, command);
                command.Parameters.Add(new SqlParameter("@id", help.Id));

                connection.Open();
                command.ExecuteNonQuery();
            }

            MatchUrls_DeleteByHelpId(help.Id);
            MatchUrls_CreateByHelpId(help.Id, help.MatchUrls);
        }
コード例 #4
0
ファイル: ModelFactory.cs プロジェクト: vebin/DocMAH
        public FirstTimeHelp CreateFirstTimeHelp(
            int id = 0,
            string matchUrls = null
            )
        {
            var result = new FirstTimeHelp
            {
                Id = id,
                Content = "Test content for first time help.",
                HorizontalOffset = 20,
                VerticalOffset = 20,
                OffsetElementId = "TestPageOffsetElementId",
                MatchUrls = matchUrls ?? string.Format("/Test/Run-{0}*", _firstTimeHelpCount),
                SourceUrl = string.Format("/Test/Run/{0}", _firstTimeHelpCount),
                Title = string.Format("Unit Test Help {0}", _firstTimeHelpCount.ToString("00#")),
            };

            _firstTimeHelpCount++;

            return result;
        }
コード例 #5
0
        private IEnumerable<FirstTimeHelp> HydratePages(SqlDataReader reader)
        {
            var idOrdinal = reader.GetOrdinal("Id");
            var sourceUrlOrdinal = reader.GetOrdinal("SourceUrl");
            var titleOrdinal = reader.GetOrdinal("Title");
            var contentOrdinal = reader.GetOrdinal("Content");
            var verticalOffsetOrdinal = reader.GetOrdinal("VerticalOffset");
            var horizontalOffsetOrdinal = reader.GetOrdinal("HorizontalOffset");
            var offsetElementIdOrdinal = reader.GetOrdinal("OffsetElementId");

            while (reader.Read())
            {
                var result = new FirstTimeHelp
                {
                    Id = reader.GetInt32(idOrdinal),
                    SourceUrl = reader.GetString(sourceUrlOrdinal),
                    Title = reader.GetString(titleOrdinal),
                    Content = reader.GetString(contentOrdinal),
                    VerticalOffset = reader.GetInt32(verticalOffsetOrdinal),
                    HorizontalOffset = reader.GetInt32(horizontalOffsetOrdinal),
                    OffsetElementId = reader.GetString(offsetElementIdOrdinal),
                };

                result.MatchUrls = MatchUrls_ReadByHelpId(result.Id);
                yield return result;
            }
        }
コード例 #6
0
 private static void AddParameters(FirstTimeHelp help, SqlCommand command)
 {
     command.Parameters.AddRange(new SqlParameter[] {
         new SqlParameter("@sourceUrl", help.SourceUrl),
         new SqlParameter("@title", help.Title),
         new SqlParameter("@content", help.Content),
         new SqlParameter("@verticalOffset", help.VerticalOffset),
         new SqlParameter("@horizontalOffset", help.HorizontalOffset),
         new SqlParameter("@offsetElementId", help.OffsetElementId),
     });
 }