예제 #1
0
        public void SplitIntoHunksTest()
        {
            var result = DiffAnalyzer.SplitIntoHunks(
                @"diff --git a/ProTagger/PTagger.cs b/ProTagger/PTagger.cs
index ecddd45..cc38031 100644
--- a/ProTagger/PTagger.cs
+++ b/ProTagger/PTagger.cs
@@ -29,15 +29,15 @@ namespace ProTagger
             }
         }

-        private RepositoryViewModel? _repository;
-        public RepositoryViewModel? Repository
+        private Variant<RepositoryViewModel, string> _repository = new Variant<RepositoryViewModel, string>(""No repository selected."");
+        public Variant<RepositoryViewModel, string> Repository
         {
             get { return _repository; }
             set
             {
                 if (_repository == value)
                     return;
-                _repository?.Dispose();
+                (_repository?.Get() as IDisposable)?.Dispose();
                 _repository = value;
                 NotifyPropertyChanged();
             }
@@ -45,7 +45,7 @@ namespace ProTagger

         public ICommand RefreshCommand { get; }

-        public IObservable<RepositoryViewModel> RepositoryObservable { get; }
+        public IObservable<Variant<RepositoryViewModel, string>> RepositoryObservable { get; }

         public PTagger(IRepositoryFactory repositoryFactory, ISchedulers schedulers)
         {
@@ -91,7 +91,7 @@ namespace ProTagger
         private readonly CompositeDisposable _disposable = new CompositeDisposable();
         public void Dispose()
         {
-            _repository?.Dispose();
+            (_repository?.Get() as IDisposable)?.Dispose();
             _disposable.Dispose();
         }
     }", new System.Threading.CancellationToken());

            Assert.AreEqual(3, result.Count);
            Assert.AreEqual(14, result[0].Diff.Count);
            Assert.IsTrue(result[0].Diff[3].Is <DiffAnalyzer.WordDiff>());
            Assert.AreEqual(2, result[0].Diff[3].Get <DiffAnalyzer.WordDiff>().NewText.Count);
            Assert.AreEqual(2, result[0].Diff[3].Get <DiffAnalyzer.WordDiff>().OldText.Count);
            Assert.AreEqual(29, result[0].NewBeginLine);
            Assert.AreEqual(29, result[0].OldBeginLine);
            Assert.AreEqual(15, result[0].NewHunkLength);
            Assert.AreEqual(15, result[0].OldHunkLength);
            Assert.AreEqual("namespace ProTagger", result[0].AdditionalInfo);
        }
예제 #2
0
        public void SplitLineTest()
        {
            var result = DiffAnalyzer.SplitLine("Ein brauner(Hund   legt,,Eier").ToList();

            Assert.AreEqual(9, result.Count, "Unexpected number of tokens");
            Assert.AreEqual("Ein", result[0]);
            Assert.AreEqual(" ", result[1]);
            Assert.AreEqual("brauner", result[2]);
            Assert.AreEqual("(", result[3]);
            Assert.AreEqual("Hund", result[4]);
            Assert.AreEqual("   ", result[5]);
            Assert.AreEqual("legt", result[6]);
            Assert.AreEqual(",,", result[7]);
            Assert.AreEqual("Eier", result[8]);
        }
예제 #3
0
        public void UpdatedUser(Guid id, string name, string email, string login, string password, bool active,
                                Role role, User loggedUser)
        {
            var userRepository = new UserRepository(_context);
            var user           = userRepository.GetById(id);
            var userByAccount  = userRepository.GetByLogin(login);

            if (userByAccount != null && userByAccount.Id != id)
            {
                throw new ApplicationException(Resource.AnotherUserToThisLoginException);
            }

            User updatedUser = null;

            switch (role)
            {
            case Role.Admin:
                updatedUser = new Admin();
                break;

            case Role.Teacher:
                updatedUser = new Teacher();
                break;

            case Role.Student:
                updatedUser = new Student();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(role), role, null);
            }


            updatedUser.Id       = id;
            updatedUser.Name     = name;
            updatedUser.Active   = active;
            updatedUser.Password = password != user.Password ? _crypt.Encrypt(password) : password;

            updatedUser.Login     = login;
            updatedUser.Email     = email;
            updatedUser.CreatedAt = user.CreatedAt;


            var analyzer    = new DiffAnalyzer();
            var differences = analyzer.Compare(_context.UnProxy(user), updatedUser);


            var diffText = new StringBuilder($"{Resource.PersonalInfoUpdatedTitle}:{Environment.NewLine}<br />");
            //foreach (var item in differences)
            //    diffText.AppendLine(item.PropertyName == "Password"
            //        ? $"- {Resource.PasswordUpdatedNoticeMessage} <br />"
            //        : $"- {item.PropertyName} {Resource.PersonalInfoUpdatedFrom} {item.OldValue} {Resource.PersonalInfoUpdatedTo} {item.NewValue}<br />");

            var updatingNotice = new Notice
            {
                Text     = diffText.ToString(),
                DateTime = DateTime.Now,
                User     = user
            };

            _context.GetList <Notice>().Add(updatingNotice);
            _context.Update(user, updatedUser);
            _context.Save(loggedUser);
        }
예제 #4
0
        public void TestMethod1()
        {
            var before = new Usuario
            {
                Id       = 1,
                Nome     = "Michael",
                Apelidos = new List <string>
                {
                    "Mike",
                    "MK"
                },
                Enderecos = new List <Endereco>
                {
                    new Endereco()
                    {
                        Logradouro = "1st street",
                        UF         = new UF()
                        {
                            Nome    = "SP",
                            Cidades = new[]
                            {
                                new Cidade
                                {
                                    Nome = "Sao Paulo"
                                },
                                new Cidade
                                {
                                    Nome = "Santos"
                                }
                            },
                        },
                    },
                },
                Telefones = new List <Telefone>
                {
                    new Telefone()
                    {
                        DDD    = "11",
                        Numero = "91234-5678",
                        Tipo   = TipoTelefone.Celular
                    }
                }
            };

            var after = new Usuario
            {
                Id       = 1,
                Nome     = "Michael",
                Apelidos = new List <string>
                {
                    "None",
                },
                Telefones = new List <Telefone>
                {
                    new Telefone()
                    {
                        DDD    = "11",
                        Numero = "1234-5678",
                        Tipo   = TipoTelefone.Comercial
                    }
                }
            };


            var analyzer = new DiffAnalyzer();
            var results  = analyzer.Compare(before, after);
        }
예제 #5
0
 public void TestInitialize()
 {
     //Initialize the global diff manager used on all tests
     _diffAnalyzer = new DiffAnalyzer();
 }