This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package crypto_test | |
import ( | |
"go_web_server/pkg/crypto" | |
"testing" | |
) | |
func Test_Hash(t *testing.T) { | |
t.Run("Can hash and compare", should_be_able_to_hash_and_compare_strings) | |
t.Run("Can detect unequal hashes", should_return_error_when_comparing_unequal_hashes) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package crypto | |
import ( | |
"errors" | |
"strings" | |
"github.com/google/uuid" | |
"golang.org/x/crypto/bcrypt" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package root | |
type Hash interface { | |
Generate(s string) (string, error) | |
Compare(hash string, s string) error | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mockUserService = new MockUserService(); | |
var mockResultService = new MockResultService(); | |
var testTime = new DateTime(1,1,2000); | |
var resultGenerator = new ResultGenerator(mockUserService, mockResultService, testTime); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TesableResultGenerator : ResultGenerator | |
{ | |
private IUserService _userService; | |
private IResultService _resultService; | |
private DateTime _dateTime; | |
public TestableResultGenerator(IUserService userService, IResultService resultService, DateTime dateTime) | |
: base() { | |
_userService = userService; | |
_resultService = resultService; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text; | |
using System; | |
namespace BigLegacyApplication | |
{ | |
internal class ReportGenerator | |
{ | |
public ReportGenerator(){} | |
internal string GetUserReport(int userId) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mockUserService = new MockUserService(); | |
var mockResultService = new MockResultService(); | |
var resultGenerator = new ResultGenerator(); | |
resultGenerator.userService = mockUserService; | |
resultGenerator.mockResultService = mockResultService; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private readonly IUserService _userService; | |
public IUserService userService { | |
get { | |
if(_userService == null) | |
_userService = new UserService(); | |
return _userService; | |
} | |
set { _userService = value; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal interface IUserService | |
{ | |
User GetUser(int userId); | |
} | |
internal interface IResultService | |
{ | |
string[] GetUserResults(int userId); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text; | |
using System; | |
namespace BigLegacyApplication | |
{ | |
internal class ReportGenerator | |
{ | |
public ReportGenerator() | |
{ | |
} |