public void AddAddressToUserShouldAddAddressDataCorrectly() { var options = new DbContextOptionsBuilder <XeonDbContext>() .UseInMemoryDatabase(databaseName: "Address_AddAddressToUser_Database") .Options; var dbContext = new XeonDbContext(options); var username = "******"; var user = new XeonUser { UserName = username }; dbContext.Users.Add(user); dbContext.SaveChanges(); var userService = new Mock <IUsersService>(); userService.Setup(r => r.GetUserByUsername(username)) .Returns(dbContext.Users.FirstOrDefault(x => x.UserName == username)); var addressService = new AddressesService(userService.Object, dbContext); var address = new Address { Street = "Ivan Vazov", Description = "106", BuildingNumber = "A", City = new City { Name = "Burgas", Postcode = "8000" }, Country = "Bulgaria" }; addressService.AddAddressToUser(username, address); var userAddress = dbContext.Users .FirstOrDefault(x => x.UserName == username) .Addresses .FirstOrDefault(); Assert.Equal(address.Street, userAddress.Street); Assert.Equal(address.Description, userAddress.Description); Assert.Equal(address.BuildingNumber, userAddress.BuildingNumber); Assert.Equal(address.Country, userAddress.Country); Assert.Equal(address.City.Name, userAddress.City.Name); Assert.Equal(address.City.Postcode, userAddress.City.Postcode); }