Exemple #1
0
        public async Task ShouldCreate_EmployeeAddress_Using_CreateEmployeeAddressInfoCommand()
        {
            Employee employee = await _dbContext.Employees.FindAsync(new Guid("e6b86ea3-6479-48a2-b8d4-54bd6cbbdbc5"));

            var command = new CreateEmployeeAddressInfo
            {
                EmployeeId   = employee.Id,
                AddressLine1 = "32145 Main Stree",
                AddressLine2 = "3rd Floor",
                City         = "Dallas",
                StateCode    = "TX",
                Zipcode      = "75021"
            };

            await _employeeCmdHdlr.Handle(command);

            var address = (from item in employee.Addresses()
                           where item.AddressDetails.AddressLine1.Equals(command.AddressLine1) &&
                           item.AddressDetails.AddressLine2.Equals(command.AddressLine2) &&
                           item.AddressDetails.City.Equals(command.City) &&
                           item.AddressDetails.StateCode.Equals(command.StateCode) &&
                           item.AddressDetails.Zipcode.Equals(command.Zipcode)
                           select item).SingleOrDefault();

            Assert.NotNull(address);
        }
Exemple #2
0
        public async Task ShouldRaiseError_Creating_Duplicate_EmployeeAddressInfo()
        {
            Employee employee = await _dbContext.Employees.FindAsync(new Guid("e6b86ea3-6479-48a2-b8d4-54bd6cbbdbc5"));

            var command = new CreateEmployeeAddressInfo
            {
                EmployeeId   = new Guid("4b900a74-e2d9-4837-b9a4-9e828752716e"),
                AddressLine1 = "321 Tarrant Pl",
                AddressLine2 = null,
                City         = "Fort Worth",
                StateCode    = "TX",
                Zipcode      = "78965"
            };

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await _employeeCmdHdlr.Handle(command));
        }
Exemple #3
0
        public async Task ShouldRaiseError_CreateEmployeeAddressInfo_With_Invalid_EmployeeId()
        {
            Employee employee = await _dbContext.Employees.FindAsync(new Guid("e6b86ea3-6479-48a2-b8d4-54bd6cbbdbc5"));

            var command = new CreateEmployeeAddressInfo
            {
                EmployeeId   = new Guid("12345a74-e2d9-4837-b9a4-9e828752716e"),
                AddressLine1 = "32145 Main Stree",
                AddressLine2 = "3rd Floor",
                City         = "Dallas",
                StateCode    = "TX",
                Zipcode      = "75021"
            };

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await _employeeCmdHdlr.Handle(command));
        }
        public async Task ShouldCreate_EmployeeAddressInfo_UsingEmployeeController()
        {
            Guid employeeId = new Guid("604536a1-e734-49c4-96b3-9dfef7417f9a");
            var  command    = new CreateEmployeeAddressInfo
            {
                EmployeeId   = employeeId,
                AddressLine1 = "5558 Reiger Street",
                AddressLine2 = "3rd Floor",
                City         = "Dallas",
                StateCode    = "TX",
                Zipcode      = "75214"
            };

            string      jsonEmployee = JsonConvert.SerializeObject(command);
            HttpContent content      = new StringContent(jsonEmployee, Encoding.UTF8, "application/json");
            var         response     = await _client.PostAsync($"{_serviceAddress}{_rootAddress}/{employeeId}/createemployeeaddressinfo", content);

            Assert.True(response.IsSuccessStatusCode);
        }
Exemple #5
0
        public async Task <IActionResult> CreateEmployeeAddressInfo([FromBody] CreateEmployeeAddressInfo writeModel)
        {
            try
            {
                await _employeeCmdHdlr.Handle(writeModel);

                GetEmployeeAddress queryParams = new GetEmployeeAddress {
                    AddressID = writeModel.AddressId
                };

                IActionResult retValue = await _employeeQryReqHdler.Handle <GetEmployeeAddress>(queryParams, HttpContext, Response);

                return(CreatedAtAction(nameof(GetEmployeeAddress), new { addressId = writeModel.AddressId }, (retValue as OkObjectResult).Value));
            }
            catch (Exception ex)
            {
                _logger.LogError($"An exception has been thrown: {ex}");
                return(BadRequest(ex.Message));
            }
        }