Пример #1
0
        public void CallConvertTimeTest()
        {
            Mock <IDateTimeConverter> dateTimeConverterMock = new Mock <IDateTimeConverter>(MockBehavior.Strict);

            dateTimeConverterMock.Setup(f => f.Convert("123")).Returns(It.IsAny <DateTime>());
            IRepositoryPost repositoryPost = new SocialTrading.Service.Repositories.Repository(new RepositoryUserAuth(), new RepositoryUserSettings());

            var fields = repositoryPost.GetType().GetRuntimeFields().ToList();

            foreach (var item in fields)
            {
                if (item.Name.Equals("_converter"))
                {
                    item.SetValue(repositoryPost, dateTimeConverterMock.Object);
                    break;
                }
            }

            var posts = new Dictionary <string, DataModelPost>
            {
                {
                    "123", new DataModelPost("123", "123", "123", "123", "123", 123.123f, "123", "123",
                                             "123", "123", "123", "123", "123", "123", 12, 123, true)
                }
            };

            repositoryPost.SetPosts(posts);

            repositoryPost.GetPostHeaderModelById("123");

            dateTimeConverterMock.Verify(f => f.Convert("123"), Times.AtLeastOnce);
        }
Пример #2
0
        public void CallConvertTimeTestNever()
        {
            Mock <IDateTimeConverter> dateTimeConverterMock = new Mock <IDateTimeConverter>(MockBehavior.Strict);

            dateTimeConverterMock.Setup(f => f.Convert(It.IsAny <string>()));
            IRepositoryPost repositoryPost = new SocialTrading.Service.Repositories.Repository(new RepositoryUserAuth(), new RepositoryUserSettings());


            var posts = new Dictionary <string, DataModelPost>
            {
                {
                    "123", new DataModelPost("123", "123", "123", "123", "123", 123.123f, "123", "123",
                                             "123", "123", "123", "123", "123", "123", 12, 123, true)
                }
            };

            repositoryPost.SetPosts(posts);

            repositoryPost.GetPostHeaderModelById("321");

            dateTimeConverterMock.Verify(f => f.Convert(It.IsAny <string>()), Times.Never);
        }