예제 #1
0
        public async Task GetById_PersonWithIdInRepository_ReturnsSuccessWithPerson()
        {
            //Arrange
            const int Id       = 0;
            Person    expected = PersonGenerator.Generate();

            expected.Id = Id;

            Mock <IPersonRepository> repository = new Mock <IPersonRepository>();

            repository.Setup(r => r.GetAsync(Id))
            .Returns(Task.FromResult(expected));

            PersonController controller = new PersonController(repository.Object);

            //Act
            IActionResult result = await controller.Get(Id);

            //Assert


            ObjectResult resultWithValue = Assert.IsType <ObjectResult>(result);
            Person       actual          = Assert.IsType <Person>(resultWithValue.Value);

            Assert.Equal(expected, actual, PersonEqualityComparer.Default);
        }
        public async Task <ActionResult <Person> > GetPersonAsync()
        {
            Task <Person> getPersonTask = PersonGenerator.GetPersonAsync();
            Person        p             = await getPersonTask;

            return(p);
        }
예제 #3
0
        public void GeneratePerson_CreatesMalePersonCorrectly()
        {
            PersonGenerator personGenerator = new PersonGenerator();
            Person          p = personGenerator.GenerateMalePerson();

            Assert.NotEqual("", p.FirstName);
            Assert.NotEqual("", p.LastName);
        }
예제 #4
0
 public PersonsController(PersonContext context, ILogger <PersonsController> logger)
 {
     _context = context;
     _logger  = logger;
     if (!_context.Persons.Any())
     {
         PersonGenerator.InitData(_context);
     }
 }
예제 #5
0
 private void FillList()
 {
     for (int i = 0; i < dailyQueue.queue.Length; i++)
     {
         if (dailyQueue.queue[i] == null)
         {
             var sex = (Sex)Random.Range(0, 1);
             dailyQueue.queue[i] = PersonGenerator.GenerateRandomPerson(sex);
         }
     }
 }
예제 #6
0
        public async Task Put_NoPeopleInRepository_ReturnsNotFound()
        {
            Mock <IPersonRepository> repository = new Mock <IPersonRepository>();
            PersonController         controller = new PersonController(repository.Object);
            Person person = PersonGenerator.Generate();

            //Act
            IActionResult result = await controller.Put(0, person);

            //Assert
            Assert.IsType <NotFoundResult>(result);
        }
예제 #7
0
 public static IEnumerable <Customer> GetCustomers()
 {
     return(Enumerable.Range(1, 15).Select(i => new Customer
     {
         FirstName = PersonGenerator.GenerateRandomFirstName(),
         LastName = PersonGenerator.GenerateRandomLastName(),
         Age = RandomGenerator.Next(25, 85),
         DateOfBirth = StartDate.AddDays(RandomGenerator.Next(DateRange)),
         Gender = Genders[RandomGenerator.Next(0, Genders.Length)],
         CreatedDate = StartDate.AddDays(RandomGenerator.Next(DateRange)),
         UpdatedDate = StartDate.AddDays(RandomGenerator.Next(DateRange))
     }));
 }
예제 #8
0
        private CustomerModel GetFakePerson(int userId)
        {
            var fakePerson = new PersonGenerator().GetNewPerson();

            return(new CustomerModel
            {
                Fullname = fakePerson.FullName,
                EmailAddress = fakePerson.Email,
                Gender = fakePerson.Gender,
                Phone = fakePerson.Phone,
                UserId = userId
            });
        }
예제 #9
0
        public async Task GetAllAsync_MultiplePeopleInContext_ReturnsMultipleItems()
        {
            //Arrange
            IEnumerable <Person> expected      = PersonGenerator.Generate(10);
            PersonContext        personContext = await CreatePersonContextWithPeople(expected);

            PersonRepository personRepository = new PersonRepository(personContext);

            //Act
            IEnumerable <Person> actual = await personRepository.GetAllAsync();

            //Assert
            Assert.Equal(expected, actual);
        }
예제 #10
0
        public void Next_Test()
        {
            IPersonGenerator target = new PersonGenerator(1);

            var person = target.Next();

            Assert.AreEqual("Zuzka", person.FirstName);
            Assert.AreEqual("Hobza", person.LastName);
            Assert.AreEqual("*****@*****.**", person.Mail);

            person = target.Next();
            Assert.AreEqual("Milan", person.FirstName);
            Assert.AreEqual("Hobza", person.LastName);
            Assert.AreEqual("*****@*****.**", person.Mail);
        }
예제 #11
0
        public async Task RemoveAsync_PersonExistsInContext_RemovesFromContext()
        {
            //Arrange
            Person        original      = PersonGenerator.Generate();
            PersonContext personContext = await CreatePersonContextWithPeople(original);

            PersonRepository personRepository = new PersonRepository(personContext);

            //Act
            Person entity = await personRepository.RemoveAsync(original.Id);

            //Assert
            Assert.NotNull(entity);
            Assert.Empty(personContext.People);
        }
예제 #12
0
        public void NextMore_Test()
        {
            IPersonGenerator target = new PersonGenerator(1);

            var persons = target.Next(5).ToList();

            Assert.AreEqual(5, persons.Count);
            Assert.AreEqual("Zuzka", persons[0].FirstName);
            Assert.AreEqual("Hobza", persons[0].LastName);
            Assert.AreEqual("*****@*****.**", persons[0].Mail);

            Assert.AreEqual("Juraj", persons[4].FirstName);
            Assert.AreEqual("Petrák", persons[4].LastName);
            Assert.AreEqual("*****@*****.**", persons[4].Mail);
        }
예제 #13
0
    // ***************************************************************************

    private void Awake()
    {
        if (GameManager.instance != null)
        {
            Debug.LogError("Multiple instances of GameManager! Destroying duplicate.");
            this.SafeDestroy(this.gameObject);
            return;
        }

        GameManager.instance    = this;
        worldCanvasInstance     = GameObject.Instantiate <WorldCanvas>(worldCanvasPrefab);
        personGeneratorInstance = GameObject.Instantiate <PersonGenerator>(personGeneratorPrefab);

        ResetVariables();
    }
예제 #14
0
        public async Task RemoveAsync_PersonNotInContext_ReturnsNullAndNoEntriesRemoved()
        {
            //Arrange
            Person        original      = PersonGenerator.Generate();
            Person        entryToRemove = PersonGenerator.Generate();
            PersonContext personContext = await CreatePersonContextWithPeople(original);

            PersonRepository personRepository = new PersonRepository(personContext);

            //Act
            Person entity = await personRepository.RemoveAsync(entryToRemove.Id);

            //Assert
            Assert.Null(entity);
            Assert.NotEmpty(personContext.People);
        }
예제 #15
0
    private void OnDestroy()
    {
        GameManager.instance = null;

        if (worldCanvasInstance != null)
        {
            this.SafeDestroy(worldCanvasInstance);
            worldCanvasInstance = null;
        }

        if (personGeneratorInstance != null)
        {
            this.SafeDestroy(personGeneratorInstance);
            personGeneratorInstance = null;
        }
    }
예제 #16
0
        public async Task GetAsync_IdExistsInContext_ReturnsPerson()
        {
            //Arrange
            const int ExpectedId = 1;
            Person    expected   = PersonGenerator.Generate();

            PersonContext personContext = await CreatePersonContextWithPeople(expected);

            PersonRepository personRepository = new PersonRepository(personContext);

            //Act
            Person actual = await personRepository.GetAsync(ExpectedId);

            //Assert
            Assert.Equal(expected, actual, PersonEqualityComparer.Default);
        }
예제 #17
0
        public async Task Get_MultiplePeopleInRepository_ReturnsAllItems()
        {
            //Arrange
            IEnumerable <Person>     people     = PersonGenerator.Generate(5);
            Mock <IPersonRepository> repository = new Mock <IPersonRepository>();

            repository.Setup(r => r.GetAllAsync()).Returns(Task.FromResult(people));

            PersonController controller = new PersonController(repository.Object);

            //Act
            IEnumerable <Person> result = await controller.Get();

            //Assert
            Assert.Equal(people, result);
        }
예제 #18
0
        public async Task Delete_ValidIdMatchingPersonInRepository_ReturnsOk()
        {
            Person person = PersonGenerator.Generate();

            Mock <IPersonRepository> repository = new Mock <IPersonRepository>();

            repository.Setup(r => r.RemoveAsync(It.IsAny <int>())).Returns(Task.FromResult(person));

            PersonController controller = new PersonController(repository.Object);

            //Act
            IActionResult result = await controller.Delete(0);

            //Assert
            Assert.IsType <OkResult>(result);
        }
예제 #19
0
        public async Task Get_SinglePersonInRepository_ReturnsSinglePerson()
        {
            //Arrange
            Mock <IPersonRepository> repository = new Mock <IPersonRepository>();

            repository.Setup(r => r.GetAllAsync())
            .Returns(Task.FromResult <IEnumerable <Person> >(new [] { PersonGenerator.Generate() }));

            PersonController controller = new PersonController(repository.Object);

            //Act
            IEnumerable <Person> result = await controller.Get();

            //Assert
            Assert.Single(result);
        }
예제 #20
0
        public async Task Put_ValidPersonWithExistingInRepository_ReturnsOk()
        {
            Person person = PersonGenerator.Generate();

            Mock <IPersonRepository> repository = new Mock <IPersonRepository>();

            repository.Setup(r => r.GetAsync(It.IsAny <int>())).Returns(Task.FromResult(person));

            PersonController controller = new PersonController(repository.Object);

            //Act
            IActionResult result = await controller.Put(0, person);

            //Assert
            Assert.IsType <OkResult>(result);
        }
예제 #21
0
        public async Task Post_PersonWithFullName_ReturnsCreatedAtResult()
        {
            //Arrange
            Person expected = PersonGenerator.Generate();
            Mock <IPersonRepository> repository = new Mock <IPersonRepository>();
            PersonController         controller = new PersonController(repository.Object);

            //Act
            IActionResult result = await controller.Post(expected);

            //Assert
            CreatedAtActionResult createdAtActionResult = Assert.IsType <CreatedAtActionResult>(result);

            Assert.Null(createdAtActionResult.ControllerName);
            Assert.Equal(nameof(PersonController.Get), createdAtActionResult.ActionName);
        }
예제 #22
0
        public async Task GetAllAsync_OnePersonInContext_ReturnsSingleItem()
        {
            //Arrange
            Person expected = PersonGenerator.Generate();

            PersonContext personContext = await CreatePersonContextWithPeople(expected);

            PersonRepository personRepository = new PersonRepository(personContext);

            //Act
            IEnumerable <Person> result = await personRepository.GetAllAsync();

            //Assert
            Person actual = Assert.Single(result);

            Assert.Equal(expected, actual, PersonEqualityComparer.Default);
        }
예제 #23
0
        public async Task AddAsync_NewPersonWithNoExistingPeople_ReturnsIdAndAddsToContext()
        {
            //Arrange
            Person        expected      = PersonGenerator.Generate();
            PersonContext personContext = CreatePersonContext();

            PersonRepository personRepository = new PersonRepository(personContext);

            //Act
            int result = await personRepository.AddAsync(expected);

            //Assert
            Assert.Equal(expected.Id, result);
            Person actual = personContext.People.Find(result);

            Assert.Equal(expected, actual, PersonEqualityComparer.Default);
        }
예제 #24
0
 public static IEnumerable <Employee> GetEmployees()
 {
     return(Enumerable.Range(1, 15).Select(i => new Employee
     {
         FirstName = PersonGenerator.GenerateRandomFirstName(),
         LastName = PersonGenerator.GenerateRandomLastName(),
         Age = RandomGenerator.Next(25, 85),
         DateOfBirth = StartDate.AddDays(RandomGenerator.Next(DateRange)),
         Gender = Genders[RandomGenerator.Next(0, Genders.Length)],
         CreatedDate = StartDate.AddDays(RandomGenerator.Next(DateRange)),
         UpdatedDate = StartDate.AddDays(RandomGenerator.Next(DateRange)),
         StartDate = DateTime.Today.AddYears(-RandomGenerator.Next(1, 20)).AddDays(-RandomGenerator.Next(1, 350)),
         Position = Positions[RandomGenerator.Next(1, Positions.Length)],
         Salary = RandomGenerator.Next(50000, 125000),
         VacationTotal = VacationTotal,
         VacationUsed = VacationTotal - RandomGenerator.Next(40, 70)
     }));
 }
예제 #25
0
        public async Task AddAsync_ExistingPersonWithIdAddingDuplicate_DuplicateNotAddedAndReturnsExistingId()
        {
            //Arrange
            const int     Id            = 1;
            Person        expected      = PersonGenerator.Generate();
            PersonContext personContext = await CreatePersonContextWithPeople(expected);

            PersonRepository personRepository = new PersonRepository(personContext);

            //Act
            int result = await personRepository.AddAsync(expected);

            //Assert
            Assert.Equal(Id, result);
            Person actual = Assert.Single(personContext.People);

            Assert.Equal(expected, actual, PersonEqualityComparer.Default);
        }
예제 #26
0
        static void Main(string[] args)
        {
            {
                // Zadanie 2
                Delegata d = new Delegata(Method);
                d(2, 2);

                Console.WriteLine("Wartość właściwości metod: {0}", d.Method);
                d += Method2;
                Console.WriteLine("Usunięcie Method, wyświetlenie Method2:");
                d -= Method;
                d(1, 2);
                Console.WriteLine(d.Method);

                PersonGenerator pg = new PersonGenerator();
                pg.Zdarzenie += Wyswietl;
                pg.Generate();
            }
            Console.ReadKey();
        }
예제 #27
0
        public MaterializeToClassVsRecordTest()
        {
            _database = new Database(new SqlConnection());
            _table    = new DataTable();
            _table.Columns.Add("Id", typeof(int));
            _table.Columns.Add("FirstName", typeof(string));
            _table.Columns.Add("LastName", typeof(string));
            _table.Columns.Add("Salary", typeof(double));
            _table.Columns.Add("IsEmployed", typeof(bool));

            var pg     = new PersonGenerator(22);
            var random = new Random(22);
            int id     = 0;

            foreach (IPerson person in pg.Next(1000))
            {
                _table.Rows.Add(++id, person.FirstName, person.LastName, random.NextDouble() * 1000,
                                Convert.ToBoolean(random.Next(-1, 1)));
            }
        }
예제 #28
0
        static async Task Main(string[] args)
        {
            var personGenerator = new PersonGenerator();
            var person          = personGenerator.GetNewPerson();

            var channel = GrpcChannel.ForAddress("https://localhost:5001");

            var client = new Greeter.GreeterClient(channel);

            Console.WriteLine("Hello from client");
            var input = new HelloRequest {
                Name = person.FullName
            };
            var reply = await client.SayHelloAsync(input);

            Console.WriteLine(reply.Message);

            var customerService = new Customer.CustomerClient(channel);
            var customerId      = new CustomerLookupModel {
                UserId = new Random().Next(1, 100)
            };
            var userFound = customerService.GetCustomerInfo(customerId);

            Console.WriteLine($"Name: {userFound.Fullname}\nEmailAddress:{userFound.EmailAddress}\nGender:{userFound.Gender}\nId:{userFound.UserId}");

            //var input2 = new CrowdLookupModel { UserIds = new Google.Protobuf.Collections.RepeatedField<CustomerLookupModel> { customerId, customerId } };
            var cancel = new CancellationToken();

            using (var call = customerService.GetCrowdInfoFromId(customerId))
            {
                while (await call.ResponseStream.MoveNext(cancel))
                {
                    var current = call.ResponseStream.Current;
                    Console.WriteLine($"Name: {current.Fullname}");
                }
            }



            Console.ReadLine();
        }
        public void GenerateFamilyCreatesGustavRichAsGrandfather()
        {
            PersonGenerator generator   = new PersonGenerator();
            Person          grandFather = generator.GenerateFamily().Father.Father;

            Assert.AreEqual("Gustav", grandFather.FirstName);
            Assert.AreEqual("Rich", grandFather.LastName);
            Assert.AreEqual(66, grandFather.Age);

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <PersonGenerator> _generator   = test.CreateVariable <PersonGenerator>(nameof(_generator));
            TestVariable <Person>          _grandFather = test.CreateVariable <Person>(nameof(_grandFather));

            test.Arrange(_generator, Expr(() => new PersonGenerator()));
            test.Arrange(_grandFather, Expr(_generator, g => g.GenerateFamily().Father.Father));
            test.Assert.AreEqual(Const("Gustav"), Expr(_grandFather, p => p.FirstName));
            test.Assert.AreEqual(Const("Rich"), Expr(_grandFather, p => p.LastName));
            test.Assert.AreEqual(Const(66), Expr(_grandFather, p => p.Age));
            test.Execute();
        }
        public void GenerateFamilyCreatesElsaJohnsonAsGrandMother()
        {
            PersonGenerator generator   = new PersonGenerator();
            Person          grandMother = generator.GenerateFamily().Father.Mother;

            Assert.AreEqual("Elsa", grandMother.FirstName);
            Assert.AreEqual("Johnson", grandMother.LastName);
            Assert.AreEqual(65, grandMother.Age);

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <PersonGenerator> _generator   = test.CreateVariable <PersonGenerator>(nameof(_generator));
            TestVariable <Person>          _grandMother = test.CreateVariable <Person>(nameof(_grandMother));

            test.Arrange(_generator, Expr(() => new PersonGenerator()));
            test.Arrange(_grandMother, Expr(_generator, g => g.GenerateFamily().Father.Mother));
            test.Assert.AreEqual(Const("Elsa"), Expr(_grandMother, p => p.FirstName));
            test.Assert.AreEqual(Const("Johnson"), Expr(_grandMother, p => p.LastName));
            test.Assert.AreEqual(Const(65), Expr(_grandMother, p => p.Age));
            test.Execute();
        }