コード例 #1
0
        public void Not_Add_IfUser_Exists()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "Not_Add_IfUser_Exists").Options;

            string firstName   = "Ivan",
                   middleName  = "Ivanov",
                   lastName    = "Ivanov",
                   phoneNumber = "1234567899";
            DateTime addOnDate = DateTime.Now;
            bool     isDeleted = false;

            var validationMock = new Mock <CommonValidations>();

            using (var actContext = new LibrarySystemContext(contextOptions))
            {
                var unit = new UnitOfWork(actContext);

                var townService    = new TownService(unit, validationMock.Object);
                var addressService = new AddressService(unit, validationMock.Object);
                var userService    = new UsersServices(unit, validationMock.Object);

                var town    = townService.AddTown("test");
                var address = addressService.AddAddress("test address", town);

                // Act and Assert
                userService.AddUser(firstName, middleName, lastName, phoneNumber, addOnDate, isDeleted, address);
                userService.AddUser(firstName, middleName, lastName, phoneNumber, addOnDate, isDeleted, address);
            }
        }
コード例 #2
0
ファイル: AddMembreViewModel.cs プロジェクト: arbaes/uwp-aout
        private async void AddMembre()
        {
            InitError();
            UsersServices usersServices = new UsersServices();

            try
            {
                bool response = await usersServices.AddUser(User);

                if (response)
                {
                    _navigationService.NavigateTo("Membres");
                    MessengerInstance.Send(new NotificationMessage(NotificationMessageType.ListUser));
                }
            }
            catch (BadRequestException e)
            {
                List <Error> errors = e.Errors.ToList();
                foreach (Error error in errors)
                {
                    SwitchError(error);
                }
            }
            catch (Exception e)
            {
                SetGeneralErrorMessage(e);
            }
        }
コード例 #3
0
        private async void AddMembre()
        {
            InitError();
            UsersServices  usersServices = new UsersServices();
            ResponseObject response      = await usersServices.AddUser(User);

            if (response.Success)
            {
                _navigationService.NavigateTo("Membres");
                MessengerInstance.Send(new NotificationMessage(NotificationMessageType.ListUser));
            }
            else
            {
                List <Error> errors = (List <Error>)response.Content;
                foreach (Error error in errors)
                {
                    SwitchError(error);
                }
            }
        }
コード例 #4
0
        public void List_Users_IfUsers_Exist()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "List_Users")
                                 .Options;

            string firstName        = "Ivan",
                   middleName       = "Ivanov",
                   lastName         = "Ivanov",
                   phoneNumber      = "1234567899";
            DateTime addOnDate      = DateTime.Now;
            bool     isDeleted      = false;
            string   fullName       = firstName + " " + middleName + " " + lastName;
            var      validationMock = new Mock <CommonValidations>();

            using (var actContext = new LibrarySystemContext(contextOptions))
            {
                var unit           = new UnitOfWork(actContext);
                var townService    = new TownService(unit, validationMock.Object);
                var addressService = new AddressService(unit, validationMock.Object);
                var userService    = new UsersServices(unit, validationMock.Object);

                var town    = townService.AddTown("test");
                var address = addressService.AddAddress("test address", town);

                userService.AddUser(firstName, middleName, lastName, phoneNumber, addOnDate, isDeleted, address);
            }
            using (var assertContext = new LibrarySystemContext(contextOptions))
            {
                var unit        = new UnitOfWork(assertContext);
                var userService = new UsersServices(unit, validationMock.Object);

                //Act & Assert
                var count = userService.ListUsers(false).Count();
                Assert.AreEqual(1, count);
                Assert.AreEqual(fullName, userService.ListUsers(false).First().FullName);
            }
        }