Пример #1
0
        public void ShouldNotAddUserIfItExists()
        {
            var          userTableRepository = Substitute.For <IUserTableRepository>();
            UsersService usersService        = new UsersService(userTableRepository);
            UserInfo     args = new UserInfo
            {
                Name    = "Vasya",
                SurName = "Pypckin",
                Balance = 50000,
                Phone   = "88005553535"
            };

            usersService.AddNewUser(args);
            userTableRepository.Contains(Arg.Is <UserEntity>(
                                             u => u.Name == args.Name &&
                                             u.SurName == args.SurName &&
                                             u.Balance == args.Balance &&
                                             u.Phone == args.Phone)).Returns(true);

            usersService.AddNewUser(args);
        }
Пример #2
0
        public void ShouldAddNewUser()
        {
            var          userTableRepository = Substitute.For <IUserTableRepository>();
            UsersService usersService        = new UsersService(userTableRepository);
            UserInfo     args = new UserInfo
            {
                Name    = "Vasya",
                SurName = "Pypckin",
                Balance = 50000,
                Phone   = "88005553535"
            };

            int userId = usersService.AddNewUser(args);

            userTableRepository.Received(1).Add(Arg.Is <UserEntity>(
                                                    u => u.Name == args.Name &&
                                                    u.SurName == args.SurName &&
                                                    u.Balance == args.Balance &&
                                                    u.Phone == args.Phone));
            userTableRepository.Received(1).SaveChanges();
        }