Пример #1
0
        public async Task WhenCallingRepositoryCreate_ShouldPassProvidedFiscalData()
        {
            // Arrange
            var input = new FiscalData();

            var validator  = new Mock <IValidator <IFiscalData> >();
            var repository = new Mock <IFiscalDataRepository>();

            validator
            .Setup(x => x.IsValid(It.IsAny <IFiscalData>()))
            .Returns(true);

            // Note: This doesn't use It.IsAny<>, but the object reference instead.
            // This will cause the .Verify() to fail if any other IFiscalData (or null) is passed
            repository
            .Setup(x => x.CreateItem(input))
            .Returns(Task.FromResult(0))
            .Verifiable();

            // Act
            await new FiscalDataService(repository.Object, validator.Object).CreateFiscalData(input);

            // Assert
            repository.Verify();
        }
        public override FiscalDataItem GetData(FiscalData dataItem, int optArgs)
        {
            string result = "";

            VerifyResult(_cco.GetData((int)dataItem, out optArgs, out result));
            return(new FiscalDataItem(result, optArgs));
        }
Пример #3
0
        public async void Option1____WhenGivenADateTimeOtherThanMinValue_ShouldPassItToRepository()
        {
            /* Option 1
             * ================
             *
             * To inspect the expression passed in, we'll use a Callback in Moq to interrogate the parameter sent to
             * the Repository's GetItems method.
             *
             * Rather than parse the Expression Tree, we'll compile it and pass in  some values that would prove it's
             * doing what we expect.
             *
             * I'm not a big fan of this, since we're "blackbox" testing the Expression, which works, but  isn't ideal.
             *
             * Also, this test is now HUGE in comparison to other tests.
             */

            // Arrange

            // Note: Rather than using just "DateTime.Today", I'm randomizing the date. This way, if the SUT has
            // "DateTime.Today" hardcoded, the test will fail.
            var rando      = new Random().Next(1, 100);
            var input      = DateTime.Today.AddDays(rando);
            var repository = new Mock <IFiscalDataRepository>();

            repository
            .Setup(x => x.GetItems(It.IsAny <Expression <Func <IFiscalData, bool> > >()))
            .Returns(Task.FromResult((IEnumerable <IFiscalData>) new IFiscalData[] { }))
            .Callback <Expression <Func <IFiscalData, bool> > >(expr =>
            {
                // Assert
                var compiledExpr = expr.Compile();

                var matchingDate = new FiscalData {
                    Date = input
                };
                var nonMatchingDate1 = new FiscalData {
                    Date = input.AddDays(1)
                };
                var nonMatchingDate2 = new FiscalData {
                    Date = input.AddDays(-1)
                };

                var matchingResult     = compiledExpr(matchingDate);
                var nonMatchingResult1 = compiledExpr(nonMatchingDate1);
                var nonMatchingResult2 = compiledExpr(nonMatchingDate2);

                Assert.True(matchingResult);
                Assert.False(nonMatchingResult1);
                Assert.False(nonMatchingResult2);
            });

            // Act
            var service = new FiscalDataService(repository.Object, null);
            await service.GetFiscalData(input);
        }
Пример #4
0
        public async void ShouldReturnTheFiscalDataObjectFromTheRepository()
        {
            // Arrange
            var expected   = new FiscalData();
            var repository = new Mock <IFiscalDataRepository>();

            repository
            .Setup(x => x.GetItems(It.IsAny <Expression <Func <IFiscalData, bool> > >()))
            .Returns(Task.FromResult((IEnumerable <IFiscalData>) new[] { expected }));

            // Act
            var service = new FiscalDataService(repository.Object, null);
            var actual  = await service.GetFiscalData(DateTime.Today);

            // Assert
            Assert.Equal(expected, actual);
        }
Пример #5
0
        public async void AddNewPatient()
        {
            Value = true;
            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Warning,
                    Languages.CheckConnection,
                    Languages.Ok);

                return;
            }
            if (string.IsNullOrEmpty(FirstName) || string.IsNullOrEmpty(LastName) || string.IsNullOrEmpty(FiscalCode))
            {
                Value = true;
                return;
            }
            if (Client == null || Residence == null || Domicile == null)
            {
                Value = true;
                return;
            }
            if (SelectedTitle.Key == null)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Please Select Title", "ok");

                return;
            }
            if (SelectedSex.Key == null)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Please Select Gender", "ok");

                return;
            }

            var _fiscalData = new FiscalData
            {
                codeDestinaterio            = CodeDestinatario,
                inderizioPec                = InderizioPec,
                adresseFacturation          = BillingAddress,
                conditionPaymentDescription = NotePayment,
                conditionPayment            = "CCD",
                pIVA = PIVA
            };
            var _domicile = new AddDomicile
            {
                comuniLocal = Domicile,
                street      = StreetDomicile
            };
            var _residence = new AddResidence
            {
                comuniLocal = Residence,
                street      = StreetResidence
            };
            var addPatient = new AddPatient
            {
                title        = SelectedTitle.Key,
                firstName    = FirstName,
                lastName     = LastName,
                fullName     = SelectedTitle.Key + " " + FirstName + " " + LastName,
                fiscalCode   = FiscalCode,
                gender       = SelectedSex.Key,
                birthDate    = DateNow, //Convert.ToDateTime(DateNow),
                placeOfBirth = PlaceOfBirth,
                note         = Note,
                phone        = Phone,
                cellPhone    = CellPhone,
                email        = Email,
                //fiscalData = _fiscalData,
                client    = Client,
                domicile  = _domicile,
                residence = _residence
            };
            var cookie = Settings.Cookie;  //.Split(11, 33)
            var res    = cookie.Substring(11, 32);

            var response = await apiService.Save <AddPatient>(
                "https://portalesp.smart-path.it",
                "/Portalesp",
                "/patient/save",
                res,
                addPatient);

            Debug.WriteLine("********responseIn ViewModel*************");
            Debug.WriteLine(response);

            /* if (!response.IsSuccess)
             * {
             *   await Application.Current.MainPage.DisplayAlert("Error", response.Message, "ok");
             *   return;
             * }*/
            Value = false;
            MessagingCenter.Send((App)Application.Current, "OnSaved");
            DependencyService.Get <INotification>().CreateNotification("PortalSP", "Patient Added");
            await Navigation.PopAsync();
        }
Пример #6
0
        public async void EditPatient()
        {
            Value = true;
            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Warning,
                    Languages.CheckConnection,
                    Languages.Ok);

                return;
            }
            if (string.IsNullOrEmpty(Patient.firstName) || string.IsNullOrEmpty(Patient.lastName) || string.IsNullOrEmpty(Patient.fiscalCode))
            {
                Value = true;
                return;
            }
            if (Patient.client == null || Patient.residence == null || Patient.domicile == null)
            {
                Value = true;
                return;
            }
            if (SelectedTitle.Key == null)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Please Select Title", "ok");

                return;
            }
            if (SelectedSex.Key == null)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Please Select Gender", "ok");

                return;
            }
            var _gender = new Gender
            {
                enumType = "eu.smartpath.portalesp.enums.Gender",
                name     = SelectedSex.Key
            };
            var _fiscalData = new FiscalData
            {
                id = Patient.fiscalData.id,
                codeDestinaterio            = Patient.fiscalData.codeDestinaterio,
                inderizioPec                = Patient.fiscalData.inderizioPec,
                adresseFacturation          = Patient.fiscalData.adresseFacturation,
                conditionPaymentDescription = Patient.fiscalData.conditionPaymentDescription,
                pIVA = Patient.fiscalData.pIVA
            };
            var _domicile = new Domicile
            {
                id          = Patient.domicile.id,
                comuniLocal = Patient.domicile.comuniLocal,
                street      = Patient.domicile.street
            };
            var _residence = new Residence
            {
                id          = Patient.residence.id,
                comuniLocal = Patient.residence.comuniLocal,
                street      = Patient.residence.street
            };
            var patient = new Patient
            {
                id                = Patient.id,
                title             = Patient.title, // SelectedTitle.Key,
                firstName         = Patient.firstName,
                lastName          = Patient.lastName,
                fullName          = Patient.fullName,
                fiscalCode        = Patient.fiscalCode,
                gender            = _gender, //Patient.gender,
                birthDate         = Patient.birthDate,
                placeOfBirth      = Patient.placeOfBirth,
                client            = Patient.client,
                phone             = Patient.phone,
                cellPhone         = Patient.cellPhone,
                email             = Patient.email,
                note              = Patient.note,
                fiscalData        = _fiscalData,
                domicile          = _domicile,
                residence         = _residence,
                confirmSave       = false,
                isMerged          = false,
                isRepositorySaved = false
            };
            var cookie = Settings.Cookie;  //.Split(11, 33)
            var res    = cookie.Substring(11, 32);

            var response = await apiService.PutPatient <Patient>(
                "https://portalesp.smart-path.it",
                "/Portalesp",
                "/patient/update",
                res,
                patient);

            Debug.WriteLine("********responseIn ViewModel*************");
            Debug.WriteLine(response);

            /* if (!response.IsSuccess)
             * {
             *   await Application.Current.MainPage.DisplayAlert("Error", response.Message, "ok");
             *   return;
             * }*/
            Value = false;
            PatientViewModel.GetInstance().Update(patient);
            MessagingCenter.Send((App)Application.Current, "OnSaved");
            DependencyService.Get <INotification>().CreateNotification("PortalSP", "Patient Updated");
            await Navigation.PopAsync();
        }