Exemplo n.º 1
0
        public void Logout_PropertiesSet()
        {
            // Setup
            var connectivitySetup = new Mock <IConnectivity>();

            var isLoggedIn          = false;
            var settingsManagerMock = new Mock <ISettingsManager>();

            settingsManagerMock.SetupSet(x => x.IsLoggedInToBackupService = It.IsAny <bool>()).Callback((bool val) => isLoggedIn = val);

            var logoutCommandCalled = false;

            var backupManagerSetup = new Mock <IBackupManager>();

            backupManagerSetup.Setup(x => x.Logout()).Callback(() => logoutCommandCalled = true).Returns(Task.CompletedTask);

            //execute
            var vm = new BackupViewModel(backupManagerSetup.Object, null, connectivitySetup.Object,
                                         settingsManagerMock.Object,
                                         new Mock <IMvxLogProvider>().Object,
                                         new Mock <IMvxNavigationService>().Object);

            vm.LogoutCommand.Execute();

            //assert
            logoutCommandCalled.ShouldBeTrue();
            isLoggedIn.ShouldBeFalse();
        }
Exemplo n.º 2
0
        public ActionResult Backup()
        {
            BackupViewModel model = new BackupViewModel();

            model.YearData  = new List <int>();
            model.MonthData = new List <Services.Models.DropDownData>();
            model.PlantData = this._plantService.GetAllPlants();
            model.PlantData.Insert(0, new Data.Models.Plant {
                Id = 0, Name = "--ALL--"
            });
            for (int i = 0; i < 15; i++)
            {
                model.YearData.Add(DateTime.Now.Year - i);
            }

            model.MonthData.Add(new Services.Models.DropDownData {
                Id = 0, Name = "-- ALL --"
            });
            for (int i = 1; i <= 12; i++)
            {
                var dt = new DateTime(2000, i, 1);
                model.MonthData.Add(new Services.Models.DropDownData {
                    Id = i, Name = dt.ToString("MMM")
                });
            }
            model.PlantId = 0;
            model.Year    = DateTime.Now.Year;
            model.Month   = DateTime.Now.Month;
            return(View(model));
        }
Exemplo n.º 3
0
        public async Task Initialize_ConnectivityNotLoggedIn_NothingCalled()
        {
            // Setup
            var connectivitySetup = new Mock <IConnectivityAdapter>();

            connectivitySetup.Setup(x => x.IsConnected).Returns(true);

            var settingsManagerMock = new Mock <ISettingsFacade>();

            settingsManagerMock.SetupAllProperties();

            var checkBackupCalled   = false;
            var getBackupDateCalled = false;

            var backupServiceMock = new Mock <IBackupService>();

            backupServiceMock.Setup(x => x.IsBackupExistingAsync()).Callback(() => checkBackupCalled = true);
            backupServiceMock.Setup(x => x.GetBackupDateAsync()).Callback(() => getBackupDateCalled  = true);

            //execute
            var vm = new BackupViewModel(backupServiceMock.Object,
                                         null,
                                         connectivitySetup.Object,
                                         settingsManagerMock.Object);
            await vm.InitializeCommand.ExecuteAsync();

            //assert
            vm.IsLoadingBackupAvailability.ShouldBeFalse();
            checkBackupCalled.ShouldBeFalse();
            getBackupDateCalled.ShouldBeFalse();
        }
Exemplo n.º 4
0
        public async Task Initialize_ConnectivityLoggedIn_MethodsCalled()
        {
            // Setup
            var connectivitySetup = new Mock <IConnectivityAdapter>();

            connectivitySetup.Setup(x => x.IsConnected).Returns(true);

            var settingsManagerMock = new Mock <ISettingsFacade>();

            settingsManagerMock.SetupGet(x => x.IsLoggedInToBackupService).Returns(true);

            DateTime returnDate = DateTime.Today;

            var backupServiceMock = new Mock <IBackupService>();

            backupServiceMock.Setup(x => x.IsBackupExistingAsync()).Returns(Task.FromResult(true));
            backupServiceMock.Setup(x => x.GetBackupDateAsync()).Returns(Task.FromResult(returnDate));

            //execute
            var vm = new BackupViewModel(backupServiceMock.Object,
                                         null,
                                         connectivitySetup.Object,
                                         settingsManagerMock.Object);
            await vm.InitializeCommand.ExecuteAsync();

            //assert
            vm.IsLoadingBackupAvailability.ShouldBeFalse();
            vm.BackupAvailable.ShouldBeTrue();
            vm.BackupLastModified.ShouldEqual(returnDate);
        }
Exemplo n.º 5
0
        public async void Loaded_ConnectivityLoggedIn_MethodsCalled()
        {
            // Setup
            var connectivitySetup = new Mock <IConnectivity>();

            connectivitySetup.Setup(x => x.IsConnected).Returns(true);

            var settingsManagerMock = new Mock <ISettingsManager>();

            settingsManagerMock.SetupGet(x => x.IsLoggedInToBackupService).Returns(true);

            var returnDate = DateTime.Today;

            var backupManagerSetup = new Mock <IBackupManager>();

            backupManagerSetup.Setup(x => x.IsBackupExisting()).Returns(Task.FromResult(true));
            backupManagerSetup.Setup(x => x.GetBackupDate()).Returns(Task.FromResult(returnDate));

            //execute
            var vm = new BackupViewModel(backupManagerSetup.Object, null, connectivitySetup.Object,
                                         settingsManagerMock.Object,
                                         new Mock <IMvxLogProvider>().Object,
                                         new Mock <IMvxNavigationService>().Object);
            await vm.Initialize();

            //assert
            vm.IsLoadingBackupAvailability.ShouldBeFalse();
            vm.BackupAvailable.ShouldBeTrue();
            vm.BackupLastModified.ShouldEqual(returnDate);
        }
Exemplo n.º 6
0
        public void Loaded_NoConnectivity_NothingCalled()
        {
            // Setup
            var connectivitySetup = new Mock <IConnectivity>();

            connectivitySetup.Setup(x => x.IsConnected).Returns(false);

            var settingsManagerMock = new Mock <ISettingsManager>();

            settingsManagerMock.SetupAllProperties();

            var checkBackupCalled   = false;
            var getBackupDateCalled = false;

            var backupManagerSetup = new Mock <IBackupManager>();

            backupManagerSetup.Setup(x => x.IsBackupExisting()).Callback(() => checkBackupCalled = true);
            backupManagerSetup.Setup(x => x.GetBackupDate()).Callback(() => getBackupDateCalled  = true);

            //execute
            var vm = new BackupViewModel(backupManagerSetup.Object, null, connectivitySetup.Object, settingsManagerMock.Object);

            vm.LoadedCommand.Execute();

            //assert
            vm.IsLoadingBackupAvailability.ShouldBeFalse();
            checkBackupCalled.ShouldBeFalse();
            getBackupDateCalled.ShouldBeFalse();
        }
Exemplo n.º 7
0
        public void Loaded_ConnectivityNotLoggedIn_NothingCalled()
        {
            // Setup
            var connectivitySetup = new Mock <IConnectivity>();

            connectivitySetup.Setup(x => x.IsConnected).Returns(true);

            var settingsMockSetup = new Mock <ISettings>();

            settingsMockSetup.Setup(x => x.GetValue(It.IsAny <string>(), It.IsAny <bool>(), false)).Returns(false);
            Mvx.RegisterType(() => settingsMockSetup.Object);

            var checkBackupCalled   = false;
            var getBackupDateCalled = false;

            var backupManagerSetup = new Mock <IBackupManager>();

            backupManagerSetup.Setup(x => x.IsBackupExisting()).Callback(() => checkBackupCalled = true);
            backupManagerSetup.Setup(x => x.GetBackupDate()).Callback(() => getBackupDateCalled  = true);

            //execute
            var vm = new BackupViewModel(backupManagerSetup.Object, null, connectivitySetup.Object);

            vm.LoadedCommand.Execute();

            //assert
            vm.IsLoadingBackupAvailability.ShouldBeFalse();
            checkBackupCalled.ShouldBeFalse();
            getBackupDateCalled.ShouldBeFalse();
        }
Exemplo n.º 8
0
        public void Loaded_ConnectivityLoggedIn_MethodsCalled()
        {
            // Setup
            var connectivitySetup = new Mock <IConnectivity>();

            connectivitySetup.Setup(x => x.IsConnected).Returns(true);

            var settingsMockSetup = new Mock <ISettings>();

            settingsMockSetup.SetupAllProperties();
            settingsMockSetup.Setup(x => x.GetValue(It.IsAny <string>(), It.IsAny <bool>(), false)).Returns(true);
            Mvx.RegisterType(() => settingsMockSetup.Object);

            var returnDate = DateTime.Today;

            var backupManagerSetup = new Mock <IBackupManager>();

            backupManagerSetup.Setup(x => x.IsBackupExisting()).Returns(Task.FromResult(true));
            backupManagerSetup.Setup(x => x.GetBackupDate()).Returns(Task.FromResult(returnDate));

            //execute
            var vm = new BackupViewModel(backupManagerSetup.Object, null, connectivitySetup.Object);

            vm.LoadedCommand.Execute();

            //assert
            vm.IsLoadingBackupAvailability.ShouldBeFalse();
            vm.BackupAvailable.ShouldBeTrue();
            vm.BackupLastModified.ShouldBe(returnDate);
        }
Exemplo n.º 9
0
        public void Initialize_ConnectivityLoggedIn_MethodsCalled()
        {
            // Setup
            var connectivitySetup = Substitute.For <IConnectivityAdapter>();

            connectivitySetup.IsConnected.Returns(true);

            var settingsManagerMock = Substitute.For <ISettingsFacade>();

            settingsManagerMock.IsLoggedInToBackupService.Returns(true);

            DateTime returnDate = DateTime.Today;

            var backupServiceMock = Substitute.For <IBackupService>();

            backupServiceMock.IsBackupExistingAsync().Returns(true);
            backupServiceMock.GetBackupDateAsync().Returns(returnDate);

            //execute
            var vm = new BackupViewModel(backupServiceMock,
                                         null,
                                         connectivitySetup,
                                         settingsManagerMock,
                                         null);

            vm.InitializeCommand.Execute(null);

            //assert
            vm.IsLoadingBackupAvailability.Should().BeFalse();
            vm.BackupAvailable.Should().BeTrue();
            vm.BackupLastModified.Should().Be(returnDate);
        }
Exemplo n.º 10
0
        public async Task Initialize_ConnectivityNotLoggedIn_NothingCalled()
        {
            // Setup
            var connectivitySetup = Substitute.For <IConnectivityAdapter>();

            connectivitySetup.IsConnected.Returns(true);

            var settingsManagerMock = Substitute.For <ISettingsFacade>();
            var backupServiceMock   = Substitute.For <IBackupService>();

            //execute
            var vm = new BackupViewModel(backupServiceMock,
                                         null,
                                         connectivitySetup,
                                         settingsManagerMock,
                                         null);

            vm.InitializeCommand.Execute(null);

            //assert
            vm.IsLoadingBackupAvailability.Should().BeFalse();
            await backupServiceMock.Received(0).IsBackupExistingAsync();

            await backupServiceMock.Received(0).GetBackupDateAsync();
        }
Exemplo n.º 11
0
        public void Logout_PropertiesSet()
        {
            // Setup
            var connectivitySetup   = Substitute.For <IConnectivityAdapter>();
            var settingsManagerMock = Substitute.For <ISettingsFacade>();

            var logoutCommandCalled = false;

            var backupServiceMock = Substitute.For <IBackupService>();

            backupServiceMock.When(x => x.LogoutAsync())
            .Do(x => logoutCommandCalled = true);

            //execute
            var vm = new BackupViewModel(backupServiceMock,
                                         null,
                                         connectivitySetup,
                                         settingsManagerMock,
                                         null);

            vm.LogoutCommand.Execute(null);

            //assert
            logoutCommandCalled.Should().BeTrue();
            settingsManagerMock.IsLoggedInToBackupService.Should().BeFalse();
        }
Exemplo n.º 12
0
        public async Task Logout_PropertiesSet()
        {
            // Setup
            var connectivitySetup = new Mock <IConnectivityAdapter>();

            var isLoggedIn          = false;
            var settingsManagerMock = new Mock <ISettingsFacade>();

            settingsManagerMock.SetupSet(x => x.IsLoggedInToBackupService = It.IsAny <bool>()).Callback((bool val) => isLoggedIn = val);

            var logoutCommandCalled = false;

            var backupServiceMock = new Mock <IBackupService>();

            backupServiceMock.Setup(x => x.LogoutAsync())
            .Callback(() => logoutCommandCalled = true)
            .Returns(Task.CompletedTask);

            //execute
            var vm = new BackupViewModel(backupServiceMock.Object,
                                         null,
                                         connectivitySetup.Object,
                                         settingsManagerMock.Object);

            await vm.LogoutCommand.ExecuteAsync();

            //assert
            logoutCommandCalled.ShouldBeTrue();
            isLoggedIn.ShouldBeFalse();
        }
Exemplo n.º 13
0
        public async void Loaded_ConnectivityNotLoggedIn_NothingCalled()
        {
            // Setup
            var connectivitySetup = new Mock <IConnectivity>();

            connectivitySetup.Setup(x => x.IsConnected).Returns(true);

            var settingsManagerMock = new Mock <ISettingsManager>();

            settingsManagerMock.SetupAllProperties();

            var checkBackupCalled   = false;
            var getBackupDateCalled = false;

            var backupManagerSetup = new Mock <IBackupManager>();

            backupManagerSetup.Setup(x => x.IsBackupExisting()).Callback(() => checkBackupCalled = true);
            backupManagerSetup.Setup(x => x.GetBackupDate()).Callback(() => getBackupDateCalled  = true);

            //execute
            var vm = new BackupViewModel(backupManagerSetup.Object, null, connectivitySetup.Object,
                                         settingsManagerMock.Object,
                                         new Mock <IMvxLogProvider>().Object,
                                         new Mock <IMvxNavigationService>().Object);
            await vm.Initialize();

            //assert
            vm.IsLoadingBackupAvailability.ShouldBeFalse();
            checkBackupCalled.ShouldBeFalse();
            getBackupDateCalled.ShouldBeFalse();
        }
Exemplo n.º 14
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            backupViewModel = App.AppViewModel.GetBackupViewModel();

            this.DataContext = backupViewModel;
            //this.appBarMenuOneDriveLogin.IsEnabled = SetBinding()

            base.OnNavigatedTo(e);
        }
Exemplo n.º 15
0
 public ActionResult Create([Bind(Include = "SystemName,IP,FullBackupAddress,DifferentialBackupAddress,IncrementalBackupAddress")] BackupViewModel backupViewModel)
 {
     if (ModelState.IsValid)
     {
         _backupService.Add(backupViewModel.MapViewModelToModel());
         _uow.SaveChanges();
         return(Json(new { success = true }));
     }
     return(PartialView("_Create", backupViewModel));
 }
Exemplo n.º 16
0
 public ActionResult Edit([Bind(Include = "Id,SystemName,IP,FullBackupAddress,DifferentialBackupAddress,IncrementalBackupAddress")] BackupViewModel backupViewModel)
 {
     if (ModelState.IsValid)
     {
         Backup backup = _backupService.FindById(backupViewModel.Id);
         backup.SystemName                = backupViewModel.SystemName;
         backup.IP                        = backupViewModel.IP;
         backup.FullBackupAddress         = backupViewModel.FullBackupAddress;
         backup.DifferentialBackupAddress = backupViewModel.DifferentialBackupAddress;
         backup.IncrementalBackupAddress  = backupViewModel.IncrementalBackupAddress;
         _uow.SaveChanges();
         return(Json(new { success = true }));
     }
     return(PartialView("_Edit", backupViewModel));
 }
Exemplo n.º 17
0
        public async Task <IActionResult> GetBackUp()
        {
            try
            {
                BackupViewModel returnModel = new BackupViewModel();

                returnModel.BackUpString = _bOBackup.TakeBackup();
                return(Ok(new CustomResponse <BackupViewModel> {
                    Message = Global.ResponseMessages.Success, StatusCode = StatusCodes.Status200OK, Result = returnModel
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(Error.LogError(ex)));
            }
        }
Exemplo n.º 18
0
        public ActionResult Backup(BackupViewModel model)
        {
            DataBaseManager DM = new DataBaseManager();
            string          succeded;

            switch (model.Selectedid)
            {
            case 1:
                //Backup SQL Server
                try
                {
                    succeded = DM.BackupSQL();
                }
                catch (Exception)
                {
                    model.backupPath = "Hubo un error, no se pudo hacer el backup";
                    return(View("Index", model));

                    throw;
                }
                model.backupPath = "El respaldo se completo exitosamente en " + succeded;
                return(View("Index", model));

            case 2:
                //Backup MySQL
                try
                {
                    succeded = DM.BackupMySQL();
                }
                catch (Exception)
                {
                    model.backupPath = "Hubo un error, no se pudo hacer el backup";
                    return(View("Index", model));

                    throw;
                }
                model.backupPath = "El respaldo se completo exitosamente en " + succeded;
                return(View("Index", model));

            default:
                model.backupPath = "Seleciona una opcion Valida";
                return(View("Index", model));
            }
        }
Exemplo n.º 19
0
        // GET: Backup
        public ActionResult Index()
        {
            BackupViewModel model = new BackupViewModel();

            return(View(model));
        }
Exemplo n.º 20
0
 public BackupView()
 {
     InitializeComponent();
     DataContext = new BackupViewModel();
 }
Exemplo n.º 21
0
 public static Backup MapViewModelToModel(this BackupViewModel entity)
 {
     return(Mapper.Map <BackupViewModel, Backup>(entity));
 }