exercism / exercism/csharp

[authentication-system] Missing test + Identity probably should be class

Đang mở
#1,904 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C#
Star
427
Fork
383
Merge trung bình
2 ngày 2 giờ
Pull request đã merge (30 ngày)
5

Mô tả

I just mentored this exercise and found out that this exercise should probably be improved.

In Task 3 the user is asked to _"Remove the set accessor or make it private"_ and because Identity is a struct and the properties are strings it can no longer be changed (because structs are implicitly copied) but Task 4 now asks the user to prevent tempering with the Admin property (which is not possible because we prevented that in Task 3, because string is immuatble and Identity is a struct) - maybe make Identity a class and link some resources in the instructions about the difference of structs and classes in C#.

In such simple exercises I would even go as far as not to use structs at all(!) unless the exercise is about structs. Don't get me wrong `structs` are important in C# but such a niche that I would consider them an "advanced concept" because there are so many things that might be confusing for example in structs with mutable reference fields, structs that are larger than 16 bytes, etc.

Task 5 asks the user to make a defensive copy of the developer dictionary before returning it but no test tests for that.
I sent the student the following test to make sure they implement a defensive copy:

```csharp
[Fact]
public void DevelopersCantBeTamperedWith()
{
var authenticator = new Authenticator(new Identity { EyeColor = "green", Email = "admin@ex.ism" });

var devs = authenticator.GetDevelopers() as IDictionary;

try
{
devs.Add("Evil Attacker", new Identity { Email = "evil.attacker@ex.ism", EyeColor = "transparent" });
}
catch (NotSupportedException)
{
// Ignore exception from read-only dictionaries.
}

Assert.False(authenticator.GetDevelopers().ContainsKey("Evil Attacker"));
}
```

Something like that should probably be added to the exercise.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.