public void TestConversionServiceErroneousResponseFromDataService()
        {
            ConversionService serv = new ConversionService();
            using (Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create())
            {
                PdfConversion.Server.DataService.Fakes.ShimFileStatusRepositoryFactory.GetRepository = () =>
                {
                    var shim = new PdfConversion.Server.DataService.Fakes.StubIRepository<FileStatusEntity>();

                    shim.SaveChanges = () => { };
                    shim.SearchForExpressionOfFuncOfT0Boolean = a =>
                    {
                        var ls = new List<FileStatusEntity>();
                        var entity = new FileStatusEntity();
                        entity.FileState = FileState.Erroneous;
                        ls.Add(entity);
                        return ls.AsQueryable<FileStatusEntity>();
                    };

                    return shim;
                };

                var status = serv.GetFileState("test");
                Assert.IsTrue(status == PdfConversionService.API.FileState.Erroneous);
            }
        }
示例#2
0
 private void InsertFileStatusToDatabase(string file, String tempFile)
 {
     //Prepare an entity
     FileStatusEntity entity = new FileStatusEntity(file.Substring(file.LastIndexOf("\\") + 1), tempFile.Substring(tempFile.LastIndexOf("\\") + 1));
     //Connect to db and insert the entity to keep track of the work being done.
     using (var repo = FileStatusRepositoryFactory.GetRepository())
     {
         repo.Insert(entity);
         repo.SaveChanges();
     }
 }
        public void TestConversionServiceSomeListResponseFromDataService()
        {
            ConversionService serv = new ConversionService();
            using (Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create())
            {
                PdfConversion.Server.DataService.Fakes.ShimFileStatusRepositoryFactory.GetRepository = () =>
                {
                    var shim = new PdfConversion.Server.DataService.Fakes.StubIRepository<FileStatusEntity>();

                    shim.SaveChanges = () => { };
                    shim.GetAll = () =>
                    {
                        var ls = new List<FileStatusEntity>();
                        var entity = new FileStatusEntity();
                        entity.FileState = FileState.Converting;
                        ls.Add(entity);
                        ls.Add(new FileStatusEntity());
                        return ls.AsQueryable<FileStatusEntity>();
                    };

                    return shim;
                };

                var results = serv.GetAvailableFiles();
                Assert.IsTrue(results.Count() == 2);
            }
        }
 //To avoid code duplication, introduced a template method that takes a lambda expression as a hook.
 private void ChangeFileStatusTemplateMethod(string filePath, FileState state, Action<FileStatusEntity> f)
 {
     using (var repo = FileStatusRepositoryFactory.GetRepository())
     {
         var fn = filePath.Substring(filePath.LastIndexOf("\\") + 1);
         var entities = repo.SearchFor(entity => entity.PhysicalFileName.Equals(fn));
         FileStatusEntity ent = null;
         if(entities !=null)
              ent = entities.FirstOrDefault();
         if (ent == null)
         {
             ent = new FileStatusEntity("Some error ocurred", filePath);
             repo.Insert(ent);
         }
         ent.FileState = state;
         f(ent);
         repo.SaveChanges();
     }
 }