Exemplo n.º 1
0
        public void CreateCleanTask_WithNegetiveSteps_StepsSetAsMinimumDefinedSteps()
        {
            CleanTask sut = new CleanTask("E -1");

            int actualSteps = sut.Steps;

            Assert.AreEqual(CleanTask.MinSteps, actualSteps);
        }
Exemplo n.º 2
0
        public void DoClean_WithOneMoveToDownCommand_ChangeThePositionToUP()
        {
            CleanTask sut   = new CleanTask("S 1");
            Point     point = new Point(1, 2);

            point = sut.DoClean(point, _Logger.Object);

            Assert.AreEqual(1, point.Y);
        }
Exemplo n.º 3
0
        public void DoClean_WithTwoMoveToUPCommand_ChangeThePositionToUP()
        {
            CleanTask sut   = new CleanTask("N 2");
            Point     point = new Point(1, 1);

            point = sut.DoClean(point, _Logger.Object);

            Assert.AreEqual(3, point.Y);
        }
Exemplo n.º 4
0
        public void DoClean_WithOneMoveToEastCommand_ChangeThePositionToUP()
        {
            CleanTask sut   = new CleanTask("E 1");
            Point     point = new Point(1, 1);

            point = sut.DoClean(point, _Logger.Object);

            Assert.AreEqual(2, point.X);
        }
Exemplo n.º 5
0
        public void CreateCleanTask_WithValidInput_PropertiesSetCorrectly()
        {
            CleanTask sut = new CleanTask("E 12");

            int actualSteps = sut.Steps;

            Assert.AreEqual(12, actualSteps);

            Direction direction = sut.Direction;

            Assert.AreEqual(direction, Direction.E);
        }
Exemplo n.º 6
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(Server.MapPath("~") + @"\Web.config"));

            ///定时清理任务
            CleanTask t = new CleanTask();

            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Exemplo n.º 7
0
        public void Clean(string sessionId, CleanArg arg = null)
        {
            _arg = arg ?? new CleanArg();
            init();
            try
            {
                log.LogDebug("开始进行清理任务。sessionId: " + sessionId);
                task  = _db.Task.SingleOrDefault(x => x.Id == sessionId);
                _tick = TimeTic(task.CreateTime);
                if (task == null)
                {
                    log.LogDebug("库中未找到清理任务,任务结束。sessionId: " + sessionId);
                    return;
                }
                task.Content = (_arg.Content ?? Config.MessagePrefix) + "\r\n\r\n\r\n" + (_arg.Suffix ?? Config.MessageSuffix);
                CheckLogin();
                if (task.Status != CleanStatus.Logined)
                {
                    debug("长时间未扫码,取消本次任务");
                    return;
                }

                InitLoginInfo();
                InitLoginUser();
                SyncContact();
                SyncCheck();
                SendMsg();
                while (!_stopSync)
                {
                }                      //等待最后一次同步完成
                Complete();
                //SyncMsg();
            }
            catch (Exception ex)
            {
                task.Status = CleanStatus.Error;
                update();
                log.LogError(1, ex, "清理过程中发生错误, sessionId: " + task.Id);
                throw;
            }
            finally
            {
                _stopSync = true;
                _http.Dispose();
                _db.Dispose();
            }
        }
Exemplo n.º 8
0
        public static CleanTask CreateTask(HttpProxy proxy, Account account, WechatContext context)
        {
            var now       = DateTime.Now;
            var url       = Urls.SessionUrl + TimeTic(now);
            var result    = proxy.Get(url);
            var sessionId = result.Split(new[] { "\"" }, StringSplitOptions.None)[1];
            var task      = new CleanTask
            {
                Id         = sessionId,
                Creator    = account,
                CreateTime = now
            };

            context.Add(task);
            context.SaveChanges();
            return(task);
        }
Exemplo n.º 9
0
        public void WhenBuildingCleanTaskWithNameAndDirectoryPath__ShouldReturnConfiguredCleanTask()
        {
            const string pathToDirectory = "Path/To/Directory";
            const string expectedId      = "taskId";
            const string expectedName    = "taskName";

            CleanTaskBuilder sut = new CleanTaskBuilder(new MockFileSystem());

            CleanTask task = (CleanTask)sut
                             .With("Id", expectedId)
                             .With("Name", expectedName)
                             .With("Path", pathToDirectory)
                             .Build();

            Assert.AreEqual(expectedId, task.Id);
            Assert.AreEqual(expectedName, task.Name);
            Assert.AreEqual(pathToDirectory, task.Path);
        }
Exemplo n.º 10
0
 public void CreateCleanTask_WithTooManySpace_ThrowException()
 {
     Assert.Throws <FormatException>(() => { CleanTask sut = new CleanTask("N    12"); });
 }
Exemplo n.º 11
0
 public void CreateCleanTask_WithInvalidCommandWithoutSpace_ThrowException()
 {
     Assert.Throws <IndexOutOfRangeException>(() => { CleanTask sut = new CleanTask("N12"); });
 }
Exemplo n.º 12
0
 public void CreateCleanTask_WithInvalidDirection_ThrowException()
 {
     Assert.Throws <InvalidEnumTypeInception>(() => { CleanTask sut = new CleanTask("X 12"); });
 }
Exemplo n.º 13
0
 public CleanTaskBuilder(IFileSystem fileSystem = null)
 {
     _cleanTask = new CleanTask(fileSystem ?? new FileSystem());
 }
Exemplo n.º 14
0
 public void SetUp()
 {
     _fileSystem = new MockFileSystem();
     _assertions = new FileSystemAssertions(_fileSystem);
     _sut        = new CleanTask(_fileSystem);
 }